naturalize

Crates.ionaturalize
lib.rsnaturalize
version0.1.2
sourcesrc
created_at2020-02-05 18:56:48.724708
updated_at2020-03-04 00:56:44.265696
descriptionConvert a string to a convenient view for natural sorting.
homepage
repositoryhttps://github.com/perdumonocle/naturalize.git
max_upload_size
id205276
size9,067
(perdumonocle)

documentation

README

naturalize

Build Status Latest Version Docs

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");
Commit count: 10

cargo fmt