12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ use core:: fmt;
16
+
15
17
use common_exception:: ErrorCode ;
16
18
use common_exception:: Result ;
17
19
use serde:: Deserialize ;
@@ -25,7 +27,7 @@ pub struct UserSetting {
25
27
pub value : UserSettingValue ,
26
28
}
27
29
28
- #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , Eq ) ]
30
+ #[ derive( Serialize , Deserialize , Clone , PartialEq , Eq ) ]
29
31
pub enum UserSettingValue {
30
32
UInt64 ( u64 ) ,
31
33
String ( Vec < u8 > ) ,
@@ -53,6 +55,32 @@ impl UserSettingValue {
53
55
}
54
56
}
55
57
58
+ impl fmt:: Display for UserSettingValue {
59
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
60
+ match self {
61
+ UserSettingValue :: UInt64 ( v) => write ! ( f, "{}" , v) ,
62
+ UserSettingValue :: String ( v) => match std:: str:: from_utf8 ( v) {
63
+ Ok ( v) => write ! ( f, "{}" , v) ,
64
+ Err ( _e) => {
65
+ for c in v {
66
+ write ! ( f, "{:02x}" , c) ?;
67
+ }
68
+ Ok ( ( ) )
69
+ }
70
+ } ,
71
+ }
72
+ }
73
+ }
74
+
75
+ impl fmt:: Debug for UserSettingValue {
76
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
77
+ match self {
78
+ UserSettingValue :: UInt64 ( v) => write ! ( f, "{}" , v) ,
79
+ UserSettingValue :: String ( _) => write ! ( f, "{}" , self ) ,
80
+ }
81
+ }
82
+ }
83
+
56
84
impl UserSetting {
57
85
pub fn create ( name : & str , value : UserSettingValue ) -> UserSetting {
58
86
UserSetting {
0 commit comments