#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

#31 in Data structures

Download history 31600/week @ 2019-01-21 30717/week @ 2019-01-28 28414/week @ 2019-02-04 32241/week @ 2019-02-11 32527/week @ 2019-02-18 36798/week @ 2019-02-25 36543/week @ 2019-03-04 36564/week @ 2019-03-11 38327/week @ 2019-03-18 33416/week @ 2019-03-25 38460/week @ 2019-04-01 45174/week @ 2019-04-08 39015/week @ 2019-04-15 46780/week @ 2019-04-22 39718/week @ 2019-04-29

141,904 downloads per month
Used in 1,122 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