Crate twoten

Crate twoten 

Source
Expand description

§twoten

Hash data into two bytes, and turn it into an (exactly) ten byte, human readable summary.

Summaries are:

  • A 16-bit fnv1a hash of the data
  • The first 8 bits of the hash are used to select a 6-character word. See WORDS.
  • The next 8 bits of the hash are formatted in an octal format, 000 to 377.

The resulting summary looks like JESTER-123

§Example

// `twoten_buf` is available on no-std and makes a stack string
use twoten::twoten_buf;

let name = twoten_buf(b"Hello, world!");
assert_eq!("ALFRED-035", name.as_str());
// Supports AsRef conversions
let asref: &str = &name;
assert_eq!("ALFRED-035", asref);
// `twoten_string` is available on std and makes a heap string.
// requires the `use-std` feature.
use twoten::twoten_string;

let name: String = twoten_string(b"Hello, world!");
assert_eq!("ALFRED-035", name.as_str());

§Features

Enable the use-std feature to activate std helpers

Modules§

words

Structs§

TwoTenString
A stack container for the generated name.

Functions§

twoten
Hash the given data, and return bytes that represent the produced twoten string
twoten_buf
Hash the given data, and return a stack allocated buffer that contains the string, and can be used without a heap
twoten_string
Hashes data and produces a heap allocated string