| Crates.io | portable-string |
| lib.rs | portable-string |
| version | 0.4.0 |
| created_at | 2025-10-12 03:28:59.365137+00 |
| updated_at | 2025-10-13 03:16:41.862492+00 |
| description | Static-length strings without any allocations. |
| homepage | https://github.com/metatable-void/portable-string |
| repository | https://github.com/metastable-void/portable-string |
| max_upload_size | |
| id | 1878838 |
| size | 45,103 |
This crate is no_std crate with zero dependencies.
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");
Apache 2.0 or MPL 2.0.