1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
/*
* SimpleByteUnit
*
* Copyright 2023 Xaver R.M.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
/*!
A thin encapsulate for integer primitives to facilitate a fast, simple, yet ergonomic byteunit implementation.
# Getting Started
Add 'simplebyteunit' to your 'Cargo.toml':
```toml
[dependencies]
simplebyteunit = "0.2.0"
```
## Example
Generate a human-readable, formatted ByteUnit:
```rust
use simplebyteunit::simplebyteunit::*;
let byteunit_var = 500000.to_byteunit(SI);
println!("{byteunit_var}");
```
Output:
```shell
500 kB
````
## Parsing strings into ByteUnits
And then you can parse formatted strings back into a ByteUnit
```rust
use simplebyteunit::simplebyteunit::*;
let byteunit_var: ByteUnit<i64> = "500 kB".into();
println!("{byteunit_var}");
```
Output:
```shell
500 kB
````
## Simple arithmetic operations
Addition, subtraction, multiplication, subtraction, and division are supported on this type.
```rust
use simplebyteunit::simplebyteunit::*;
let a: ByteUnit<i64> = ByteUnit::SI(5000000);
let b: ByteUnit<i64> = ByteUnit::SI(5000000);
let byteunit_sum = a + b;
println!("{byteunit_sum}");
```
Output:
```shell
1.0 MB
```
## Equal/and/or operations
Equal operations are supported on this type:
```rust
use simplebyteunit::simplebyteunit::*;
let a: ByteUnit<i64> = "500 KiB".into();
let b: ByteUnit<i64> = "500 KiB".into();
let byteunit_bool = a == b;
println!("{byteunit_bool}");
```
Output:
```shell
true
````
Or operations are also supported on this type:
```rust
use simplebyteunit::simplebyteunit::*;
let a: ByteUnit<i64> = 5000000.to_byteunit(IEC);
let b: ByteUnit<i64> = 5000000.to_byteunit(IEC);
let byteunit_bool = a >= b;
println!("{byteunit_bool}");
```
Output:
```shell
true
```
*/
pub mod simplebyteunit;
mod input;
mod output;
mod test;