4 releases (breaking)
Uses new Rust 2024
| 0.4.0 | Oct 13, 2025 |
|---|---|
| 0.3.0 | Oct 12, 2025 |
| 0.2.0 | Oct 12, 2025 |
| 0.1.0 | Oct 12, 2025 |
#1928 in Data structures
17KB
328 lines
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.