Skip to content

Commit 2ed0a5d

Browse files
committed
✨ Implement FromStr for XattrName
1 parent 681316d commit 2ed0a5d

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

lib/src/entry/attr.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//! Extended attribute types for PNA archive entries.
22
33
use crate::util::bounded::{LengthExceeded, bytes::BoundedBytes, str::BoundedString};
4-
use std::{io, mem, ops::Deref, str};
4+
use std::{
5+
io, mem,
6+
ops::Deref,
7+
str::{self, FromStr},
8+
};
59

610
const XATTR_LENGTH_LIMIT: usize = u32::MAX as usize;
711

@@ -68,6 +72,15 @@ impl From<XattrName> for String {
6872
}
6973
}
7074

75+
impl FromStr for XattrName {
76+
type Err = LengthExceeded;
77+
78+
#[inline]
79+
fn from_str(s: &str) -> Result<Self, Self::Err> {
80+
Self::new(s)
81+
}
82+
}
83+
7184
/// Extended-attribute value (arbitrary bytes).
7285
///
7386
/// Bounded by the `u32` length prefix used in the `xATR` chunk's serialized
@@ -254,6 +267,12 @@ mod tests {
254267
assert_eq!(String::from(name), "user.foo");
255268
}
256269

270+
#[test]
271+
fn xattr_name_parses_from_str() {
272+
let name: XattrName = "user.comment".parse().unwrap();
273+
assert_eq!(name.as_str(), "user.comment");
274+
}
275+
257276
#[test]
258277
fn xattr_value_accepts_arbitrary_bytes() {
259278
let value = XattrValue::new(vec![0xFF, 0x00, 0x80]).unwrap();

0 commit comments

Comments
 (0)