@@ -383,6 +383,22 @@ impl Client {
383383 self
384384 }
385385
386+ /// Set an option on this instance of [`Client`].
387+ ///
388+ /// Returns the previous value for the option, if one was set.
389+ pub fn set_option (
390+ & mut self ,
391+ name : impl Into < String > ,
392+ value : impl Into < String > ,
393+ ) -> Option < String > {
394+ self . options . insert ( name. into ( ) , value. into ( ) )
395+ }
396+
397+ /// Get an option that was previously set on this `Client`.
398+ pub fn get_option ( & mut self , name : impl AsRef < str > ) -> Option < & str > {
399+ self . options . get ( name. as_ref ( ) ) . map ( String :: as_str)
400+ }
401+
386402 /// Starts a new INSERT statement.
387403 ///
388404 /// # Validation
@@ -503,12 +519,6 @@ impl Client {
503519 self . validation
504520 }
505521
506- /// Used internally to modify the options map of an _already cloned_
507- /// [`Client`] instance.
508- pub ( crate ) fn add_option ( & mut self , name : impl Into < String > , value : impl Into < String > ) {
509- self . options . insert ( name. into ( ) , value. into ( ) ) ;
510- }
511-
512522 pub ( crate ) fn set_roles ( & mut self , roles : impl IntoIterator < Item = impl Into < String > > ) {
513523 self . clear_roles ( ) ;
514524 self . roles . extend ( roles. into_iter ( ) . map ( Into :: into) ) ;
@@ -823,4 +833,16 @@ mod client_tests {
823833 let client = client. with_option ( "async_insert" , "1" ) ;
824834 assert_ne ! ( client. options, client_clone. options, ) ;
825835 }
836+
837+ #[ test]
838+ fn it_gets_options ( ) {
839+ let mut client = Client :: default ( ) ;
840+
841+ client. set_option ( "foo" , "foo" ) ;
842+ client. set_option ( "bar" , "bar" ) ;
843+
844+ assert_eq ! ( client. get_option( "foo" ) , Some ( "foo" ) ) ;
845+ assert_eq ! ( client. get_option( "bar" ) , Some ( "bar" ) ) ;
846+ assert_eq ! ( client. get_option( "baz" ) , None ) ;
847+ }
826848}
0 commit comments