3 releases
0.1.2 | Mar 4, 2020 |
---|---|
0.1.1 | Mar 3, 2020 |
0.1.0 | Feb 5, 2020 |
#294 in Value formatting
8KB
78 lines
naturalize
Convert a string to a convenient view for natural sorting.
E.g., output string may be stored into database for ordering by.
Usage
To use naturalize
, first add this to your Cargo.toml
:
[dependencies]
naturalize = "0.1"
Next, add this to your crate:
extern crate naturalize;
use naturalize::to_natural;
Examples:
use naturalize::to_natural;
let nat = to_natural("abc123def").unwrap();
assert_eq!(nat, "abc0000000123def");
use naturalize::to_natural;
let nat = to_natural("").unwrap();
assert_eq!(nat, "");
use naturalize::to_natural;
let nat = to_natural("1020").unwrap();
assert_eq!(nat, "0000001020");
use naturalize::to_natural;
let nat = to_natural("102030405060708090").unwrap();
assert_eq!(nat, "102030405060708090");
use naturalize::to_natural;
let nat = to_natural("Hello").unwrap();
assert_eq!(nat, "Hello");
use naturalize::to_natural;
let nat = to_natural("10 apples").unwrap();
assert_eq!(nat, "0000000010 apples");
use naturalize::to_natural;
let nat = to_natural("apples 10").unwrap();
assert_eq!(nat, "apples 0000000010");
use naturalize::to_natural;
let nat = to_natural("172.29.21.151").unwrap();
assert_eq!(nat, "0000000172.0000000029.0000000021.0000000151");
use naturalize::to_natural;
let nat = to_natural("IP = 172.29.21.151").unwrap();
assert_eq!(nat, "IP = 0000000172.0000000029.0000000021.0000000151");
Dependencies
~1MB
~17K SLoC