portable-string

Crates.ioportable-string
lib.rsportable-string
version0.4.0
created_at2025-10-12 03:28:59.365137+00
updated_at2025-10-13 03:16:41.862492+00
descriptionStatic-length strings without any allocations.
homepagehttps://github.com/metatable-void/portable-string
repositoryhttps://github.com/metastable-void/portable-string
max_upload_size
id1878838
size45,103
Yuka MORI (metastable-void)

documentation

README

Portable static-length string (no_std, Copy)

This crate is no_std crate with zero dependencies.

Usage

use portable_string::PortableString;

const LEN: usize = 17;
const LEN_PLUS_NULL: usize = LEN + 1;
type E = PortableString<LEN_PLUS_NULL>;

// clipping (each Japanese character mostly takes three bytes)
let ja_str = "日本國民は、正當に選󠄁擧された國會における代表者を通󠄁じて行動し、われらとわれらの子孫のために、諸國民との協和による成󠄁果と、わが國全󠄁土にわたつて自由のもたらす惠澤を確保し、政府の行爲によつて再び戰爭の慘禍が起ることのないやうにすることを決意し、ここに主權が國民に存することを宣言し、この憲󠄁法を確定する。";
let e = E::new_until_null(ja_str);
assert_eq!(e.try_as_str().unwrap(), "日本國民は");

// core::fmt usage
use core::fmt::Write;

let mut writer = PortableStringWriter::<256>::new();
write!(&mut writer, "Final answer: {}", 42).unwrap();

let str = writer.into_inner();
let str = str.try_as_str().unwrap();
assert_eq!(str, "Final answer: 42");

License

Apache 2.0 or MPL 2.0.

Commit count: 0

cargo fmt