diff options
Diffstat (limited to 'vendor/bstr/src/impls.rs')
-rw-r--r-- | vendor/bstr/src/impls.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/vendor/bstr/src/impls.rs b/vendor/bstr/src/impls.rs index 861ca5376..02ec0f21c 100644 --- a/vendor/bstr/src/impls.rs +++ b/vendor/bstr/src/impls.rs @@ -63,6 +63,7 @@ macro_rules! impl_partial_ord { mod bstring { use core::{ cmp::Ordering, convert::TryFrom, fmt, iter::FromIterator, ops, + str::FromStr, }; use alloc::{ @@ -90,6 +91,15 @@ mod bstring { } } + impl FromStr for BString { + type Err = crate::Utf8Error; + + #[inline] + fn from_str(s: &str) -> Result<BString, crate::Utf8Error> { + Ok(BString::from(s)) + } + } + impl ops::Deref for BString { type Target = Vec<u8>; @@ -1074,6 +1084,12 @@ mod display { } #[test] + fn from_str() { + let s: BString = "abc".parse().unwrap(); + assert_eq!(s, BString::new(b"abc".to_vec())); + } + + #[test] fn width_bigger_than_bstr() { assert_eq!(&format!("{:<7}!", &b"abc".as_bstr()), "abc !"); assert_eq!(&format!("{:>7}!", &b"abc".as_bstr()), " abc!"); |