@@ -33,7 +33,7 @@ macro_rules! str_check {
3333// This implementation follows the example of Path/PathBuf as closely as
3434// possible.
3535macro_rules! str_id {
36- ( $B: ident, $O: ident, $MAX: ident) => {
36+ ( $B: ident, $O: ident, $MAX: ident, $err_func : ident ) => {
3737 /// The borrowed version of the DM identifier.
3838 #[ derive( Debug , PartialEq , Eq , Hash ) ]
3939 pub struct $B {
@@ -51,9 +51,7 @@ macro_rules! str_id {
5151 #[ allow( clippy:: new_ret_no_self) ]
5252 pub fn new( value: & str ) -> DmResult <& $B> {
5353 if let Some ( err_msg) = str_check!( value, $MAX - 1 ) {
54- return Err ( DmError :: Core (
55- ErrorKind :: InvalidArgument ( err_msg. into( ) ) . into( ) ,
56- ) ) ;
54+ return Err ( $err_func( & err_msg) ) ;
5755 }
5856 Ok ( unsafe { & * ( value as * const str as * const $B) } )
5957 }
@@ -84,9 +82,7 @@ macro_rules! str_id {
8482 #[ allow( clippy:: new_ret_no_self) ]
8583 pub fn new( value: String ) -> DmResult <$O> {
8684 if let Some ( err_msg) = str_check!( & value, $MAX - 1 ) {
87- return Err ( DmError :: Core (
88- ErrorKind :: InvalidArgument ( err_msg. into( ) ) . into( ) ,
89- ) ) ;
85+ return Err ( $err_func( & err_msg) ) ;
9086 }
9187 Ok ( $O { inner: value } )
9288 }
@@ -124,8 +120,12 @@ mod tests {
124120
125121 use crate :: core:: errors:: { Error , ErrorKind } ;
126122
123+ fn err_func ( err_msg : & str ) -> DmError {
124+ DmError :: Core ( ErrorKind :: InvalidArgument ( err_msg. into ( ) ) . into ( ) )
125+ }
126+
127127 const TYPE_LEN : usize = 12 ;
128- str_id ! ( Id , IdBuf , TYPE_LEN ) ;
128+ str_id ! ( Id , IdBuf , TYPE_LEN , err_func ) ;
129129
130130 #[ test]
131131 /// Test for errors on an empty name.
0 commit comments