Crates.io | anystr |
lib.rs | anystr |
version | 0.1.1 |
source | src |
created_at | 2024-04-23 11:17:26.162015 |
updated_at | 2024-04-23 19:14:07.310619 |
description | An abstraction over string encoding that supports ASCII, UTF-8, UTF-16 and UTF-32 |
homepage | |
repository | https://github.com/bohdloss/anystr |
max_upload_size | |
id | 1217456 |
size | 34,773 |
A crate for abstracting the encoding of an owned or referenced string,
using the widestring
and ascii
crates under the hood.
It's aimed at situations where you might want to serialize/deserialize a string, or move it around, but you don't care about its encoding. Both std and no-std environments are supported.
The following encodings are currently supported:
This crate provides two main types: the AnyString
, an owned string type, and the AnyStr
which is a referenced type.
use anystr::AnyStr;
use widestring::utf16str;
let any = AnyStr::Utf16(utf16str!("Hello world, but utf-16!"));
fn print_any(str: AnyStr) {
for ch in str.chars() {
print!("{ch}");
}
println!();
}
print_any(any);
This crate will always target the latest version of rust, but it may be compatible with older versions.
With all that being said, this project was made mostly as a small personal project to be used as a tool in some situation, and is not intended to replace bigger string handling crates.