#string

string

A UTF-8 encoded string with configurable byte storage

6 releases

0.2.0 Mar 6, 2019
0.1.3 Jan 10, 2019
0.1.2 Nov 21, 2018
0.1.1 Jul 13, 2018
0.0.0 Jul 25, 2017

#7 in Data structures

Download history 19054/week @ 2018-11-21 23548/week @ 2018-11-28 25238/week @ 2018-12-05 24636/week @ 2018-12-12 14955/week @ 2018-12-19 8641/week @ 2018-12-26 20346/week @ 2019-01-02 31394/week @ 2019-01-09 32723/week @ 2019-01-16 31288/week @ 2019-01-23 30171/week @ 2019-01-30 29765/week @ 2019-02-06 32548/week @ 2019-02-13 33508/week @ 2019-02-20 37925/week @ 2019-02-27

120,993 downloads per month
Used in 940 crates (3 directly)

MIT license

11KB
157 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.2.0"

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");

Dependencies

~389KB