bytes_size 0.1.2

一个解析、计算字节单位的库
Documentation
  • Coverage
  • 5.71%
    2 out of 35 items documented1 out of 34 items with examples
  • Size
  • Source code size: 22.09 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.06 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Rehtt/BytesSize_rust
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Rehtt

计算字节单位

#[cfg(test)]
mod tests {
    use std::ops::Sub;
    use crate::size::{add, ByteSize, ByteSizeUnit};
    use std::str::FromStr;
    use super::*;

    #[test]
    fn parse() {
        assert_eq!(ByteSize::from_str("12.3 PB").unwrap().to_size(), ByteSize::pb(12.3).to_size());
        assert_eq!(ByteSize::from_str("12.3 TB").unwrap().to_size(), ByteSize::tb(12.3).to_size());
        assert_eq!(ByteSize::from_str("12.3 GB").unwrap().to_size(), ByteSize::gb(12.3).to_size());
        assert_eq!(ByteSize::from_str("12.3 MB").unwrap().to_size(), ByteSize::mb(12.3).to_size());
        assert_eq!(ByteSize::from_str("12.3 KB").unwrap().to_size(), ByteSize::kb(12.3).to_size());

        assert_eq!(ByteSize::from_str("12.3 PiB").unwrap().to_size(), ByteSize::pib(12.3).to_size());
        assert_eq!(ByteSize::from_str("12.3 TiB").unwrap().to_size(), ByteSize::tib(12.3).to_size());
        assert_eq!(ByteSize::from_str("12.3 GiB").unwrap().to_size(), ByteSize::gib(12.3).to_size());
        assert_eq!(ByteSize::from_str("12.3 MiB").unwrap().to_size(), ByteSize::mib(12.3).to_size());
        assert_eq!(ByteSize::from_str("12.3 KiB").unwrap().to_size(), ByteSize::kib(12.3).to_size());

        assert_eq!("12.3 PB",ByteSize::pb(12.3).to_pb().to_string())
    }

    #[test]
    fn convert() {
        assert_eq!(ByteSize::from_str("12.3 PB").unwrap().to_tb().to_string(), ByteSize::pb(12.3).to_tb().to_string());
        // ...
    }

    #[test]
    fn calculate(){
        let a=ByteSize::gb(2.0);
        let b=ByteSize::mb(1000.0);
        assert_eq!(add(a,b).unwrap().to_size(),ByteSize::gb(3.0).to_size())
    }
}

Record

0.1.2 添加Debug属性

0.1.1 调整文件结构,修复一些bug

0.1.0 初始化