use super::*;
#[derive(Clone, Copy)]
pub enum BytesBase {
Gabyte,
Bibyte,
}
impl Default for BytesBase {
fn default() -> Self {
BytesBase::Gabyte
}
}
#[derive(Default, Clone, Copy)]
pub(crate) struct BytesParam {
pub(crate) base: BytesBase,
pub(crate) precision: usize,
pub(crate) aligned: bool,
}
pub struct BytesConfig {
pub(crate) config: Arc<Mutex<RefCell<BytesParam>>>,
}
impl BytesConfig {
pub fn new(base: BytesBase, precision: usize, padded: bool) -> Self {
Self {
config: Arc::new(Mutex::new(RefCell::new(BytesParam {
base,
precision,
aligned: padded,
}))),
}
}
pub fn set_base(&self, b: BytesBase) {
let config = (*self.config).lock().unwrap();
config.borrow_mut().base = b;
}
pub fn set_aligned(&self, pa: bool) {
let config = (*self.config).lock().unwrap();
config.borrow_mut().aligned = pa;
}
pub fn set_precision(&self, pr: usize) {
let config = (*self.config).lock().unwrap();
config.borrow_mut().precision = pr;
}
pub fn bytes<U: Unsigned + Display + PartialOrd + Into<u64> + Copy>(&self, b: U) -> Bytes<U> {
Bytes::new(self.config.clone(), b)
}
}
impl Default for BytesConfig {
fn default() -> Self {
Self {
config: Arc::new(Mutex::new(RefCell::new(BytesParam {
base: BytesBase::default(),
precision: 2,
aligned: false,
}))),
}
}
}