@@ -3,6 +3,7 @@ cfg_feat_text! {
33}
44use super :: { BoxDynNode , BoxDynText , Elements , INodeTrait , INodeType } ;
55use crate :: mesdoc:: error:: { BoxDynError , Error as IError } ;
6+ use std:: fmt:: Display ;
67use std:: ops:: Range ;
78
89pub type BoxDynElement < ' a > = Box < dyn IElementTrait + ' a > ;
@@ -35,12 +36,12 @@ impl IAttrValue {
3536 }
3637}
3738
38- /// impl `ToString ` for IAttrValue
39- impl ToString for IAttrValue {
40- fn to_string ( & self ) -> String {
39+ /// impl `Display ` for IAttrValue
40+ impl Display for IAttrValue {
41+ fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
4142 match self {
42- IAttrValue :: Value ( v, _) => v . clone ( ) ,
43- IAttrValue :: True => String :: new ( ) ,
43+ IAttrValue :: Value ( v, _) => write ! ( f , "{v}" ) ,
44+ IAttrValue :: True => write ! ( f , "" ) ,
4445 }
4546 }
4647}
@@ -52,11 +53,11 @@ pub enum IFormValue {
5253 Multiple ( Vec < String > ) ,
5354}
5455
55- impl ToString for IFormValue {
56- fn to_string ( & self ) -> String {
56+ impl Display for IFormValue {
57+ fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
5758 match self {
58- IFormValue :: Single ( v) => v . clone ( ) ,
59- IFormValue :: Multiple ( v) => v. join ( "," ) ,
59+ IFormValue :: Single ( v) => write ! ( f , "{v}" ) ,
60+ IFormValue :: Multiple ( v) => write ! ( f , "{}" , v. join( "," ) ) ,
6061 }
6162 }
6263}
@@ -261,6 +262,7 @@ pub trait IElementTrait: INodeTrait {
261262 // element child nodes
262263 fn child_nodes_length ( & self ) -> usize ;
263264 fn child_nodes_item < ' b > ( & self , index : usize ) -> Option < BoxDynNode < ' b > > ;
265+ #[ allow( clippy:: type_complexity) ]
264266 fn child_nodes_item_since_by < ' a > (
265267 & ' a self ,
266268 node_index : usize ,
@@ -293,6 +295,7 @@ pub trait IElementTrait: INodeTrait {
293295 }
294296 result
295297 }
298+ #[ allow( clippy:: type_complexity) ]
296299 fn children_by < ' a > ( & ' a self , matcher : Box < dyn FnMut ( & dyn IElementTrait ) + ' a > ) ;
297300 // attribute
298301 fn get_attribute ( & self , name : & str ) -> Option < IAttrValue > ;
@@ -360,7 +363,7 @@ mod tests {
360363 fn test_i_attr_value ( ) {
361364 // string value
362365 let attr_value = IAttrValue :: Value ( "Hello" . into ( ) , None ) ;
363- assert ! ( format!( "{:?}" , attr_value ) . contains( "Hello" ) ) ;
366+ assert ! ( format!( "{attr_value :?}" ) . contains( "Hello" ) ) ;
364367 assert ! ( attr_value. is_str( "Hello" ) ) ;
365368 assert ! ( !attr_value. is_true( ) ) ;
366369 assert_eq ! ( attr_value. to_list( ) , vec![ "Hello" ] ) ;
0 commit comments