1- use std:: str:: FromStr ;
1+ use std:: { fmt :: Display , str:: FromStr } ;
22
33use nom:: bytes:: complete:: take;
44
@@ -7,6 +7,7 @@ use crate::{
77 error:: Error ,
88} ;
99
10+ #[ allow( clippy:: enum_variant_names) ]
1011pub enum VariableCodeSelector {
1112 ShortZeroLeadBytes ,
1213 ShortOneLeadBytes ,
@@ -53,16 +54,16 @@ impl VariableCodeSelector {
5354 }
5455 }
5556}
56- impl ToString for VariableCodeSelector {
57- fn to_string ( & self ) -> String {
58- match self {
59- VariableCodeSelector :: ShortZeroLeadBytes => "4" . to_string ( ) ,
60- VariableCodeSelector :: ShortOneLeadBytes => "5" . to_string ( ) ,
61- VariableCodeSelector :: ShortTwoLeadBytes => "6" . to_string ( ) ,
62- VariableCodeSelector :: LongZeroLeadBytes => "7" . to_string ( ) ,
63- VariableCodeSelector :: LongOneLeadBytes => "8" . to_string ( ) ,
64- VariableCodeSelector :: LongTwoLeadBytes => "9" . to_string ( ) ,
65- }
57+ impl Display for VariableCodeSelector {
58+ fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
59+ f . write_str ( match self {
60+ VariableCodeSelector :: ShortZeroLeadBytes => "4" ,
61+ VariableCodeSelector :: ShortOneLeadBytes => "5" ,
62+ VariableCodeSelector :: ShortTwoLeadBytes => "6" ,
63+ VariableCodeSelector :: LongZeroLeadBytes => "7" ,
64+ VariableCodeSelector :: LongOneLeadBytes => "8" ,
65+ VariableCodeSelector :: LongTwoLeadBytes => "9" ,
66+ } )
6667 }
6768}
6869
@@ -97,13 +98,13 @@ pub enum SmallVariableLengthCode {
9798 Base64String ,
9899}
99100
100- impl ToString for SmallVariableLengthCode {
101- fn to_string ( & self ) -> String {
102- match self {
103- SmallVariableLengthCode :: Base64String => "A" . to_string ( ) ,
104- SmallVariableLengthCode :: HPKEBaseCipher => "F" . to_string ( ) ,
105- SmallVariableLengthCode :: HPKEAuthCipher => "G" . to_string ( ) ,
106- }
101+ impl Display for SmallVariableLengthCode {
102+ fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
103+ f . write_str ( match self {
104+ SmallVariableLengthCode :: Base64String => "A" ,
105+ SmallVariableLengthCode :: HPKEBaseCipher => "F" ,
106+ SmallVariableLengthCode :: HPKEAuthCipher => "G" ,
107+ } )
107108 }
108109}
109110
@@ -126,12 +127,12 @@ pub enum LargeVariableLengthCode {
126127 HPKEAuthCipher ,
127128}
128129
129- impl ToString for LargeVariableLengthCode {
130- fn to_string ( & self ) -> String {
131- match self {
132- LargeVariableLengthCode :: HPKEBaseCipher => "AAF" . to_string ( ) ,
133- LargeVariableLengthCode :: HPKEAuthCipher => "AAG" . to_string ( ) ,
134- }
130+ impl Display for LargeVariableLengthCode {
131+ fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
132+ f . write_str ( match self {
133+ LargeVariableLengthCode :: HPKEBaseCipher => "AAF" ,
134+ LargeVariableLengthCode :: HPKEAuthCipher => "AAG" ,
135+ } )
135136 }
136137}
137138
@@ -167,11 +168,11 @@ impl VariableLengthPrimitive {
167168 0 => ( LeadBytes :: Zero , from_text_to_bytes ( encoded_value) . unwrap ( ) ) ,
168169 1 => (
169170 LeadBytes :: One ,
170- ( & from_text_to_bytes ( encoded_value) . unwrap ( ) [ 1 ..] ) . to_vec ( ) ,
171+ ( from_text_to_bytes ( encoded_value) . unwrap ( ) [ 1 ..] ) . to_vec ( ) ,
171172 ) ,
172173 2 => (
173174 LeadBytes :: Two ,
174- ( & from_text_to_bytes ( encoded_value) . unwrap ( ) [ 2 ..] ) . to_vec ( ) ,
175+ ( from_text_to_bytes ( encoded_value) . unwrap ( ) [ 2 ..] ) . to_vec ( ) ,
175176 ) ,
176177 _ => panic ! ( "Invalid leading bytes length" ) ,
177178 } ;
@@ -264,7 +265,7 @@ impl VariableLengthCode {
264265 LeadBytes :: Two => VariableCodeSelector :: ShortTwoLeadBytes ,
265266 } ;
266267 let quadlets = adjust_with_num ( * length, 2 ) ;
267- format ! ( "{}{}{}" , selector. to_string ( ) , code. to_string ( ) , quadlets)
268+ format ! ( "{}{}{}" , selector, code, quadlets)
268269 }
269270 VariableLengthCode :: Large { lb, code, length } => {
270271 let selector = match lb {
@@ -273,7 +274,7 @@ impl VariableLengthCode {
273274 LeadBytes :: Two => VariableCodeSelector :: LongTwoLeadBytes ,
274275 } ;
275276 let quadlets = adjust_with_num ( * length as u16 , 4 ) ;
276- format ! ( "{}{}{}" , selector. to_string ( ) , code. to_string ( ) , quadlets)
277+ format ! ( "{}{}{}" , selector, code, quadlets)
277278 }
278279 }
279280 }
0 commit comments