string_lit_as_bytes

This commit is contained in:
ShaharNaveh committed 2026-06-27 13:17:39 +03:00
1 parent afc11890b9
commit f40f756440
4 files changed
+24 -10

No files matched your search

+1
View File
@@ -369,6 +369,7 @@ redundant_clone = "warn"
search_is_some = "warn"
significant_drop_in_scrutinee = "warn"
single_option_map = "warn"
string_lit_as_bytes = "warn"
trait_duplication_in_bounds = "warn"
type_repetition_in_bounds = "warn"
unnecessary_struct_initialization = "warn"
+2 -2
View File
@@ -195,7 +195,7 @@ mod tests {
fn bytes_to_int_invalid_base() {
for base in [1, 37] {
assert_eq!(
bytes_to_int("012345".as_bytes(), base, DIGIT_LIMIT),
bytes_to_int(b"012345", base, DIGIT_LIMIT),
Err(BytesToIntError::InvalidBase)
)
}
@@ -204,7 +204,7 @@ mod tests {
#[test]
fn bytes_to_int_digit_limit() {
assert_eq!(
bytes_to_int("012345".as_bytes(), 10, 5),
bytes_to_int(b"012345", 10, 5),
Err(BytesToIntError::DigitLimit { got: 6, limit: 5 })
);
}
+8 -8
View File
@@ -146,7 +146,7 @@ mod _json {
macro_rules! parse_const {
($s:literal, $val:expr) => {
if rest.starts_with($s.as_bytes()) {
if rest.starts_with($s) {
return Ok(PyIterReturn::Return(
vm.new_tuple(($val, char_idx + $s.len())).into(),
));
@@ -154,9 +154,9 @@ mod _json {
};
}
parse_const!("null", vm.ctx.none());
parse_const!("true", true);
parse_const!("false", false);
parse_const!(b"null", vm.ctx.none());
parse_const!(b"true", true);
parse_const!(b"false", false);
if let Some((res, len)) = self.parse_number(rest, vm) {
return Ok(PyIterReturn::Return(
@@ -166,7 +166,7 @@ mod _json {
macro_rules! parse_constant {
($s:literal) => {
if rest.starts_with($s.as_bytes()) {
if rest.starts_with($s) {
return Ok(PyIterReturn::Return(
vm.new_tuple((
self.parse_constant.call(($s,), vm)?,
@@ -178,9 +178,9 @@ mod _json {
};
}
parse_constant!("NaN");
parse_constant!("Infinity");
parse_constant!("-Infinity");
parse_constant!(b"NaN");
parse_constant!(b"Infinity");
parse_constant!(b"-Infinity");
Ok(PyIterReturn::StopIteration(Some(
vm.ctx.new_int(char_idx).into(),
+13
View File
@@ -60,6 +60,18 @@ impl ToPyObject for Vec<u8> {
}
}
impl<const N: usize> ToPyObject for [u8; N] {
fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.new_bytes(self.into()).into()
}
}
impl<const N: usize> ToPyObject for &[u8; N] {
fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.new_bytes(self.into()).into()
}
}
impl Deref for PyBytes {
type Target = [u8];
@@ -73,6 +85,7 @@ impl AsRef<[u8]> for PyBytes {
self.as_bytes()
}
}
impl AsRef<[u8]> for PyBytesRef {
fn as_ref(&self) -> &[u8] {
self.as_bytes()