Skip to content

Commit 7759449

Browse files
committed
chore(query): fix display
1 parent 50424e0 commit 7759449

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/meta/types/src/user_setting.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use core::fmt;
16+
1517
use common_exception::ErrorCode;
1618
use common_exception::Result;
1719
use serde::Deserialize;
@@ -25,7 +27,7 @@ pub struct UserSetting {
2527
pub value: UserSettingValue,
2628
}
2729

28-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
30+
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
2931
pub enum UserSettingValue {
3032
UInt64(u64),
3133
String(Vec<u8>),
@@ -53,6 +55,32 @@ impl UserSettingValue {
5355
}
5456
}
5557

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+
5684
impl UserSetting {
5785
pub fn create(name: &str, value: UserSettingValue) -> UserSetting {
5886
UserSetting {

0 commit comments

Comments
 (0)