File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11//! Extended attribute types for PNA archive entries.
22
33use 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
610const 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 ( ) ;
You can’t perform that action at this time.
0 commit comments