hyunsik / bytesize

An utility that easily makes bytes size representation and helps its arithmetic operations.
Apache License 2.0
107 stars 31 forks source link

Feature Request: Bits #30

Open acheronfail opened 1 year ago

acheronfail commented 1 year ago

I'm using this in a network monitor context, and it's very nice to have automatic formatting into *bytes/sec - which is commonly used in things like download speeds in browsers, etc.

However, it's also very common to measure internet bandwidth in bits, i.e., a "100 megabit connection" or "100 Mbps".

I think it would be really neat if this crate could support a Bit type too, so it could format in bits as well as bytes.

acheronfail commented 1 year ago

Right now this is a workaround:

fn bits(bytes: u64, si: bool) -> String {
    let mut s = ByteSize(bytes * 8).to_string_as(si);
    s.pop();
    format!("{}bits", s)
}