@@ -108,15 +108,17 @@ impl VariableSet {
108108 return Err ( Error :: ReadOnlySecret ( name) ) ;
109109 }
110110 let variable = Variable :: new ( value, VariableKind :: Public ) ;
111- self . variables . insert ( name. to_string ( ) , variable) ;
111+ self . variables . insert ( name, variable) ;
112112 Ok ( ( ) )
113113 }
114114
115- /// Inserts a secret variable named `name` with `value` into the variable set.
115+ /// Inserts a secret variable named `name` with a string `value` into the variable set.
116116 ///
117117 /// Contrary to [`VariableSet::insert`], this method can not fail: a secret can override a
118- /// public variable and a secret variable.
119- pub fn insert_secret ( & mut self , name : String , value : Value ) {
118+ /// public variable and a secret variable. Secret are only string, that's why `value` is a
119+ /// `String` and not a `[Value::String]`.
120+ pub fn insert_secret ( & mut self , name : String , value : String ) {
121+ let value = Value :: String ( value. to_string ( ) ) ;
120122 let variable = Variable :: new ( value, VariableKind :: Secret ) ;
121123 self . variables . insert ( name, variable) ;
122124 }
@@ -126,20 +128,10 @@ impl VariableSet {
126128 self . variables . get ( name)
127129 }
128130
129- /// Returns true if the variable set contains no variables.
130- pub fn is_empty ( & self ) -> bool {
131- self . variables . is_empty ( )
132- }
133-
134131 /// Returns an iterator over all the variables values.
135132 pub fn iter ( & self ) -> impl Iterator < Item = ( & String , & Variable ) > {
136133 self . variables . iter ( )
137134 }
138-
139- /// Returns the number of variables in the set.
140- pub fn len ( & self ) -> usize {
141- self . variables . len ( )
142- }
143135}
144136
145137#[ cfg( test) ]
@@ -151,7 +143,6 @@ mod test {
151143 #[ test]
152144 fn simple_variable_set ( ) {
153145 let mut variables = VariableSet :: new ( ) ;
154- assert ! ( variables. is_empty( ) ) ;
155146
156147 variables
157148 . insert ( "foo" . to_string ( ) , Value :: String ( "xxx" . to_string ( ) ) )
@@ -165,9 +156,7 @@ mod test {
165156 variables
166157 . insert ( "baz" . to_string ( ) , Value :: Number ( Float ( 1.0 ) ) )
167158 . unwrap ( ) ;
168- variables. insert_secret ( "quic" . to_string ( ) , Value :: Number ( Integer ( 42 ) ) ) ;
169-
170- assert_eq ! ( variables. len( ) , 4 ) ;
159+ variables. insert_secret ( "quic" . to_string ( ) , "42" . to_string ( ) ) ;
171160
172161 assert_eq ! (
173162 variables. get( "foo" ) ,
@@ -191,7 +180,7 @@ mod test {
191180 assert_eq ! (
192181 variables. get( "quic" ) ,
193182 Some ( & Variable :: new(
194- Value :: Number ( Integer ( 42 ) ) ,
183+ Value :: String ( "42" . to_string ( ) ) ,
195184 VariableKind :: Secret
196185 ) )
197186 ) ;
@@ -232,7 +221,7 @@ mod test {
232221 #[ test]
233222 fn secret_cant_be_reassigned ( ) {
234223 let mut variables = VariableSet :: new ( ) ;
235- variables. insert_secret ( "foo" . to_string ( ) , Value :: Number ( Integer ( 42 ) ) ) ;
224+ variables. insert_secret ( "foo" . to_string ( ) , "42" . to_string ( ) ) ;
236225 assert ! ( variables
237226 . insert( "foo" . to_string( ) , Value :: String ( "xxx" . to_string( ) ) )
238227 . is_err( ) ) ;
0 commit comments