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

#98 in Data structures

Download history 10415/week @ 2024-07-27 10590/week @ 2024-08-03 14990/week @ 2024-08-10 10485/week @ 2024-08-17 11220/week @ 2024-08-24 10967/week @ 2024-08-31 10222/week @ 2024-09-07 9243/week @ 2024-09-14 9064/week @ 2024-09-21 8820/week @ 2024-09-28 7952/week @ 2024-10-05 9452/week @ 2024-10-12 8737/week @ 2024-10-19 10964/week @ 2024-10-26 10615/week @ 2024-11-02 9722/week @ 2024-11-09

41,788 downloads per month
Used in 1,166 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

~195KB