Skip to content

Commit

Permalink
using multiple-pymethods to write ext for bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekrubin committed Jan 31, 2025
1 parent cc2a3cc commit 068d733
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/ryo3-bytes/src/bytes_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl PyBytes {
let bslice: &[u8] = self.as_ref();
let mut s = String::with_capacity(bslice.len() * 2);
for b in bslice {
s.push_str(&format!("{:02x}", b));
s.push_str(&format!("{b:02x}"));
}
Ok(s)
}
Expand All @@ -97,12 +97,12 @@ impl PyBytes {
/// ```
#[classmethod]
fn fromhex(_cls: &Bound<'_, PyType>, s: &str) -> PyResult<Self> {
let s = s.replace(" ", "");
let s = s.replace(' ', "");
let mut bytes = Vec::new();
for i in 0..s.len() {
if i % 2 == 0 {
let byte = u8::from_str_radix(&s[i..i + 2], 16).map_err(|e| {
pyo3::exceptions::PyValueError::new_err(format!("Invalid hex string: {}", e))
pyo3::exceptions::PyValueError::new_err(format!("Invalid hex string: {e}"))
})?;
bytes.push(byte);
}
Expand Down

0 comments on commit 068d733

Please sign in to comment.