8 releases

0.3.0 Dec 2, 2021
0.2.1 Jun 27, 2019
0.2.0 Mar 6, 2019
0.1.3 Jan 10, 2019
0.0.0 Jul 25, 2017

#240 in Data structures

Download history 19616/week @ 2024-01-06 18858/week @ 2024-01-13 19943/week @ 2024-01-20 20248/week @ 2024-01-27 19765/week @ 2024-02-03 19804/week @ 2024-02-10 22911/week @ 2024-02-17 22735/week @ 2024-02-24 22831/week @ 2024-03-02 19152/week @ 2024-03-09 17683/week @ 2024-03-16 16617/week @ 2024-03-23 13224/week @ 2024-03-30 10742/week @ 2024-04-06 11328/week @ 2024-04-13 10173/week @ 2024-04-20

47,817 downloads per month
Used in 1,185 crates (2 directly)

MIT license

12KB
166 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.3.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:

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

Dependencies

~170KB