PowerTools/powertools-rs/src/settings/general.rs

44 lines
1.2 KiB
Rust
Raw Normal View History

2022-07-30 21:33:31 +01:00
use std::convert::{Into, From};
use crate::persist::SettingsJson;
use super::{Cpu, Gpu};
const LATEST_VERSION: u64 = 0;
#[derive(Debug, Clone)]
pub struct Settings {
pub persistent: bool,
pub cpus: Vec<Cpu>,
pub gpu: Gpu,
}
impl From<SettingsJson> for Settings {
#[inline]
fn from(mut other: SettingsJson) -> Self {
match other.version {
0 => Self {
persistent: other.persistent,
cpus: other.cpus.drain(..).map(|cpu| Cpu::from_json(cpu, other.version)).collect(),
gpu: Gpu::from_json(other.gpu, other.version),
},
_ => Self {
persistent: other.persistent,
cpus: other.cpus.drain(..).map(|cpu| Cpu::from_json(cpu, other.version)).collect(),
gpu: Gpu::from_json(other.gpu, other.version),
}
}
}
}
impl Into<SettingsJson> for Settings {
#[inline]
fn into(mut self) -> SettingsJson {
SettingsJson {
version: LATEST_VERSION,
persistent: self.persistent,
cpus: self.cpus.drain(..).map(|cpu| cpu.into()).collect(),
gpu: self.gpu.into()
}
}
}