@@ -84,83 +84,6 @@ fn str_check(value: &str, max_allowed_chars: usize) -> DmResult<()> {
8484 Ok ( ( ) )
8585}
8686
87- /// Define borrowed and owned versions of string types that guarantee
88- /// conformance to DM restrictions, such as maximum length.
89- // This implementation follows the example of Path/PathBuf as closely as
90- // possible.
91- macro_rules! str_id {
92- ( $B: ident, $O: ident, $MAX: ident, $check: ident) => {
93- /// The borrowed version of the DM identifier.
94- #[ derive( Debug , PartialEq , Eq , Hash ) ]
95- pub struct $B {
96- inner: str ,
97- }
98-
99- /// The owned version of the DM identifier.
100- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
101- pub struct $O {
102- inner: String ,
103- }
104-
105- impl $B {
106- /// Create a new borrowed identifier from a `&str`.
107- #[ allow( clippy:: new_ret_no_self) ]
108- pub fn new( value: & str ) -> DmResult <& $B> {
109- $check( value, $MAX - 1 ) ?;
110- Ok ( unsafe { & * ( value as * const str as * const $B) } )
111- }
112-
113- /// Get the inner value as bytes
114- pub fn as_bytes( & self ) -> & [ u8 ] {
115- self . inner. as_bytes( )
116- }
117- }
118-
119- impl ToOwned for $B {
120- type Owned = $O;
121- fn to_owned( & self ) -> $O {
122- $O {
123- inner: self . inner. to_owned( ) ,
124- }
125- }
126- }
127-
128- impl fmt:: Display for $B {
129- fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
130- write!( f, "{}" , & self . inner)
131- }
132- }
133-
134- impl $O {
135- /// Construct a new owned identifier.
136- #[ allow( clippy:: new_ret_no_self) ]
137- pub fn new( value: String ) -> DmResult <$O> {
138- $check( & value, $MAX - 1 ) ?;
139- Ok ( $O { inner: value } )
140- }
141- }
142-
143- impl AsRef <$B> for $O {
144- fn as_ref( & self ) -> & $B {
145- self
146- }
147- }
148-
149- impl Borrow <$B> for $O {
150- fn borrow( & self ) -> & $B {
151- self . deref( )
152- }
153- }
154-
155- impl Deref for $O {
156- type Target = $B;
157- fn deref( & self ) -> & $B {
158- $B:: new( & self . inner) . expect( "inner satisfies all correctness criteria for $B::new" )
159- }
160- }
161- } ;
162- }
163-
16487/// A devicemapper name. Really just a string, but also the argument type of
16588/// DevId::Name. Used in function arguments to indicate that the function
16689/// takes only a name, not a devicemapper uuid.
0 commit comments