Skip to content

Commit

Permalink
Make clippy happy (fix direct implementation of ToString)
Browse files Browse the repository at this point in the history
  • Loading branch information
azat committed Feb 12, 2024
1 parent df9669a commit e8ee5de
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/view/query_result_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,37 @@ pub enum Field {
DateTime(DateTime<Tz>),
// TODO: support more types
}
impl ToString for Field {
fn to_string(&self) -> String {
impl std::fmt::Display for Field {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// TODO: add human time formatter
let fmt_bytes = SizeFormatter::new()
// TODO: use Base10 for rows and Base2 for bytes
.with_base(Base::Base2)
.with_style(Style::Abbreviated);

match *self {
Self::String(ref value) => value.clone(),
Self::Float64(ref value) => format!("{:.2}", value),
Self::Float32(ref value) => format!("{:.2}", value),
Self::String(ref value) => write!(f, "{}", value),
Self::Float64(ref value) => write!(f, "{:.2}", value),
Self::Float32(ref value) => write!(f, "{:.2}", value),
Self::UInt64(ref value) => {
if *value < 1_000 {
return value.to_string();
write!(f, "{}", value)
} else {
write!(f, "{}", fmt_bytes.format(*value as i64))
}
return fmt_bytes.format(*value as i64);
}
Self::UInt32(ref value) => value.to_string(),
Self::UInt8(ref value) => value.to_string(),
Self::UInt32(ref value) => write!(f, "{}", value),
Self::UInt8(ref value) => write!(f, "{}", value),
Self::Int64(ref value) => {
if *value < 1_000 {
return value.to_string();
write!(f, "{}", value)
} else {
write!(f, "{}", fmt_bytes.format(*value))
}
return fmt_bytes.format(*value);
}
Self::Int32(ref value) => value.to_string(),
Self::Int8(ref value) => value.to_string(),
Self::DateTime(ref value) => value.to_string(),
Self::Int32(ref value) => write!(f, "{}", value),
Self::Int8(ref value) => write!(f, "{}", value),
Self::DateTime(ref value) => write!(f, "{}", value),
}
}
}
Expand Down

0 comments on commit e8ee5de

Please sign in to comment.