9 releases

0.3.1 Sep 13, 2024
0.3.0 Dec 2, 2021
0.2.1 Jun 27, 2019
0.2.0 Mar 6, 2019
0.0.0 Jul 25, 2017

#105 in Data structures

Download history 11067/week @ 2024-12-02 12282/week @ 2024-12-09 10470/week @ 2024-12-16 4579/week @ 2024-12-23 4057/week @ 2024-12-30 9780/week @ 2025-01-06 11147/week @ 2025-01-13 9393/week @ 2025-01-20 10991/week @ 2025-01-27 35858/week @ 2025-02-03 14624/week @ 2025-02-10 8840/week @ 2025-02-17 12021/week @ 2025-02-24 11811/week @ 2025-03-03 12929/week @ 2025-03-10 13139/week @ 2025-03-17

50,791 downloads per month
Used in 1,158 crates (via twitter-stream)

MIT license

13KB
178 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.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:

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

Dependencies

~235KB