Crates.io | naturalize |
lib.rs | naturalize |
version | 0.1.2 |
source | src |
created_at | 2020-02-05 18:56:48.724708 |
updated_at | 2020-03-04 00:56:44.265696 |
description | Convert a string to a convenient view for natural sorting. |
homepage | |
repository | https://github.com/perdumonocle/naturalize.git |
max_upload_size | |
id | 205276 |
size | 9,067 |
Convert a string to a convenient view for natural sorting.
E.g., output string may be stored into database for ordering by.
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;
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");