summaryrefslogtreecommitdiffstats
path: root/vendor/bstr/src/impls.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/bstr/src/impls.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bstr/src/impls.rs')
-rw-r--r--vendor/bstr/src/impls.rs16
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!");