refactor: clean up some unused serde code (#1619)

This commit is contained in:
Clement Tsang 2024-11-07 23:13:07 -05:00 committed by GitHub
parent 16a2fd6a41
commit ae14685913
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,5 @@
use std::{borrow::Cow, cmp::Reverse};
use serde::{de::Error, Deserialize, Serialize};
use super::ProcWidgetData;
use crate::{
canvas::components::data_table::{ColumnHeader, SortsRow},
@ -32,47 +30,6 @@ pub enum ProcColumn {
GpuUtilPercent,
}
impl<'de> Deserialize<'de> for ProcColumn {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let value = String::deserialize(deserializer)?.to_lowercase();
match value.as_str() {
"cpu%" => Ok(ProcColumn::CpuPercent),
"mem" => Ok(ProcColumn::MemoryVal),
"mem%" => Ok(ProcColumn::MemoryPercent),
"pid" => Ok(ProcColumn::Pid),
"count" => Ok(ProcColumn::Count),
"name" => Ok(ProcColumn::Name),
"command" => Ok(ProcColumn::Command),
"read" | "r/s" | "rps" => Ok(ProcColumn::ReadPerSecond),
"write" | "w/s" | "wps" => Ok(ProcColumn::WritePerSecond),
"tread" | "t.read" => Ok(ProcColumn::TotalRead),
"twrite" | "t.write" => Ok(ProcColumn::TotalWrite),
"state" => Ok(ProcColumn::State),
"user" => Ok(ProcColumn::User),
"time" => Ok(ProcColumn::Time),
#[cfg(feature = "gpu")]
"gmem" => Ok(ProcColumn::GpuMem),
#[cfg(feature = "gpu")]
"gmem%" => Ok(ProcColumn::GpuMemPercent),
#[cfg(feature = "gpu")]
"gpu%" => Ok(ProcColumn::GpuUtilPercent),
_ => Err(Error::custom("doesn't match any column type")),
}
}
}
impl Serialize for ProcColumn {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.text())
}
}
impl ColumnHeader for ProcColumn {
fn text(&self) -> Cow<'static, str> {
match self {