Skip to content

Commit

Permalink
remove an unwrap from the DeBin impl for String
Browse files Browse the repository at this point in the history
  • Loading branch information
knickish committed Apr 7, 2024
1 parent e3b56de commit 8348971
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/serde_bin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use core::convert::TryInto;
use core::hash::Hash;

use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::collections::{BTreeSet, LinkedList};
use alloc::string::{String, ToString};
use alloc::string::String;
use alloc::vec::Vec;

#[cfg(feature = "no_std")]
Expand Down Expand Up @@ -224,9 +225,16 @@ impl DeBin for String {
s: d.len(),
});
}
let r = core::str::from_utf8(&d[*o..(*o + len)])
.unwrap()
.to_string();
let r = match core::str::from_utf8(&d[*o..(*o + len)]) {
Ok(r) => r.to_owned(),
Err(_) => {
return Err(DeBinErr {
o: *o,
l: len,
s: d.len(),
})
}
};
*o += len;
Ok(r)
}
Expand Down

0 comments on commit 8348971

Please sign in to comment.