#string

string

A UTF-8 encoded string with configurable byte storage

3 unstable releases

0.1.1 Jul 13, 2018
0.1.0 Jan 12, 2018
0.0.0 Jul 25, 2017

#14 in Data structures

Download history 1538/week @ 2018-05-27 2414/week @ 2018-06-03 3768/week @ 2018-06-10 3762/week @ 2018-06-17 4281/week @ 2018-06-24 4025/week @ 2018-07-01 4556/week @ 2018-07-08 5455/week @ 2018-07-15 6239/week @ 2018-07-22 5725/week @ 2018-07-29 7166/week @ 2018-08-05 7193/week @ 2018-08-12 5576/week @ 2018-08-19

13,473 downloads per month
Used in 407 crates (1 directly)

MIT license

7KB
81 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"

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