add cg ls, prepare for rc subcommands
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
use human_units::FormatSize;
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
pub trait Human {
|
||||
fn human(&self) -> String;
|
||||
}
|
||||
|
||||
pub struct Quantity(u64);
|
||||
|
||||
impl Display for Quantity {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
self.0.format_size().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Human for Quantity {
|
||||
fn human(&self) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl Human for u64 {
|
||||
fn human(&self) -> String {
|
||||
self.format_size().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Human> Human for Option<T> {
|
||||
fn human(&self) -> String {
|
||||
match self {
|
||||
Some(h) => h.human(),
|
||||
None => "◌".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user