#string

string

A UTF-8 encoded string with configurable byte storage

5 releases

0.1.3 Jan 10, 2019
0.1.2 Nov 21, 2018
0.1.1 Jul 13, 2018
0.1.0 Jan 12, 2018
0.0.0 Jul 25, 2017

#4 in Data structures

Download history 11506/week @ 2018-10-23 18778/week @ 2018-10-30 18931/week @ 2018-11-06 17285/week @ 2018-11-13 16940/week @ 2018-11-20 19054/week @ 2018-11-27 23548/week @ 2018-12-04 25238/week @ 2018-12-11 24636/week @ 2018-12-18 16554/week @ 2018-12-25 16039/week @ 2019-01-01 23294/week @ 2019-01-08 25971/week @ 2019-01-15

85,918 downloads per month
Used in 737 crates (2 directly)

MIT license

8KB
130 lines

String

A UTF-8 encoded string with configurable byte storage.

Build Status License: MIT Crates.io Documentation

Usage

To use string, first add this to your Cargo.toml:

[dependencies]
string = "0.1.3"

Next, add this to your crate:

extern crate string;

use string::{String, TryFrom};

let s: String<[u8; 2]> = String::try_from([b'h', b'i']).unwrap();
assert_eq!(&s[..], "hi");

See documentation for more details.


lib.rs:

A UTF-8 encoded string with configurable byte storage.

This crate provides String, a type similar to its std counterpart, but with one significant difference: the underlying byte storage is configurable. In other words, String<T> is a marker type wrapping T, indicating that it represents a UTF-8 encoded string.

For example, one can represent small strings (stack allocated) by wrapping an array:

# use string::*;
let s: String<[u8; 2]> = String::try_from([b'h', b'i']).unwrap();
assert_eq!(&s[..], "hi");

No runtime deps