#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(unused_parens)]
#![allow(unused_assignments)]
#![allow(unused_mut)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![no_std]
#[cfg(feature = "std")]
#[cfg(not(feature = "no-alloc"))]
mod full_fixed;
#[cfg(feature = "std")]
#[cfg(not(feature = "no-alloc"))]
pub use full_fixed::*;
#[cfg(not(feature = "no-alloc"))]
#[cfg(any(feature = "shared-str", feature = "flex-str"))]
mod shared_structs;
#[cfg(feature = "flex-str")]
#[cfg(not(feature = "no-alloc"))]
mod flexible_string;
#[cfg(feature = "flex-str")]
#[cfg(not(feature = "no-alloc"))]
pub use flexible_string::*;
#[cfg(feature = "shared-str")]
#[cfg(not(feature = "no-alloc"))]
mod shared_string;
#[cfg(feature = "shared-str")]
#[cfg(not(feature = "no-alloc"))]
pub use shared_string::*;
mod zero_terminated;
pub use zero_terminated::*;
mod tiny_internal;
use tiny_internal::*;
#[cfg(feature = "pub_tstr")]
pub use tiny_internal::*;
#[cfg(feature = "circular-str")]
mod circular_string;
#[cfg(feature = "circular-str")]
pub use circular_string::*;
#[cfg(not(feature = "no-alloc"))]
extern crate alloc;
#[cfg(feature = "experimental")]
pub trait Fixedstr<const N:usize> {
type Target;
fn make<TA : AsRef<str>>(s:TA) -> Self::Target;
fn create<TA : AsRef<str>>(s:TA) -> Self::Target {
Self::make(s)
} fn try_make<TA:AsRef<str>>(s:TA) -> Result<Self::Target,TA> {
if s.as_ref().len()<N {Ok(Self::make(s))} else {Err(s)}
}
fn const_make(s:&str) -> Self::Target;
fn const_try_make(s:&str) -> Option<Self::Target>;
fn new() -> Self::Target {
Self::make("")
}
fn len(&self) -> usize;
fn charlen(&self) -> usize;
fn capacity(&self) -> usize { N-1 }
fn to_str(&self) -> &str;
fn as_str(&self) -> &str;
#[cfg(not(feature = "no-alloc"))]
fn to_string(&self) -> alloc::string::String {
alloc::string::String::from(self.to_str())
}
fn set(&mut self, i: usize, c: char) -> bool;
fn push_str<'t>(&mut self, src: &'t str) -> &'t str;
fn push_char(&mut self, c: char) -> bool;
fn pop_char(&mut self) -> Option<char>;
fn nth(&self, n: usize) -> Option<char>;
fn nth_bytechar(&self, n: usize) -> char;
fn truncate(&mut self, n: usize);
fn truncate_bytes(&mut self, n: usize);
fn truncate_unchecked(&mut self, n: usize);
fn clear(&mut self);
fn right_ascii_trim(&mut self);
fn make_ascii_lowercase(&mut self);
fn make_ascii_uppercase(&mut self);
fn case_insensitive_eq<TA:AsRef<str>>(&self, other: TA) -> bool;
fn is_ascii(&self) -> bool {
self.to_str().is_ascii()
}
}
#[cfg(feature = "serde")]
mod serde_support {
use super::*;
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};
macro_rules! generate_impl {
($ty: ident, $visitor: ident) => {
impl<const N: usize> Serialize for $ty<N> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(self.as_str())
}
}
impl<'de, const N: usize> Deserialize<'de> for $ty<N> {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
deserializer.deserialize_str($visitor)
}
}
struct $visitor<const N: usize>;
impl<'de, const N: usize> Visitor<'de> for $visitor<N> {
type Value = $ty<N>;
fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("a string")
}
fn visit_str<E: serde::de::Error>(self, s: &str) -> Result<Self::Value, E> {
$ty::try_make(s).map_err(|_| E::custom("string too long"))
}
}
};
}
generate_impl!(zstr, ZstrVisitor);
generate_impl!(tstr, TstrVisitor);
#[cfg(feature = "std")]
#[cfg(not(feature = "no-alloc"))]
generate_impl!(fstr, FstrVisitor);
#[cfg(feature = "flex-str")]
#[cfg(not(feature = "no-alloc"))]
generate_impl!(Flexstr, FlexstrVisitor);
#[cfg(feature = "circular-str")]
impl<const N: usize> Serialize for cstr<N> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let s = self.to_contiguous(); let (a, _) = s.to_strs();
serializer.serialize_str(a)
}
}
#[cfg(feature = "circular-str")]
struct CstrVisitor<const N: usize>;
#[cfg(feature = "circular-str")]
impl<'de, const N: usize> Visitor<'de> for CstrVisitor<N> {
type Value = cstr<N>;
fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("a string")
}
fn visit_str<E: serde::de::Error>(self, s: &str) -> Result<Self::Value, E> {
cstr::try_make(s).map_err(|_| E::custom("string too long"))
}
}
#[cfg(feature = "circular-str")]
impl<'de, const N: usize> Deserialize<'de> for cstr<N> {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
deserializer.deserialize_str(CstrVisitor)
}
}
}
pub type str8 = tstr<8>;
pub type str16 = tstr<16>;
pub type str32 = tstr<32>;
pub type str64 = tstr<64>;
pub type str128 = tstr<128>;
pub type str256 = tstr<256>;
pub type str4 = tstr<4>;
pub type str12 = tstr<12>;
pub type str24 = tstr<24>;
pub type str48 = tstr<48>;
pub type str96 = tstr<96>;
pub type str192 = tstr<192>;
#[macro_export]
macro_rules! str_format {
($ty_size:ty, $($args:tt)*) => {
{use core::fmt::Write;
let mut fstr0 = <$ty_size>::new();
let res=write!(&mut fstr0, $($args)*);
fstr0}
};
}
#[macro_export]
macro_rules! try_format {
($ty_size:ty, $($args:tt)*) => {
{use core::fmt::Write;
let mut fstr0 = <$ty_size>::new();
let result = write!(&mut fstr0, $($args)*);
if result.is_ok() {Some(fstr0)} else {None}}
};
}
#[macro_export]
macro_rules! to_fixedstr {
($ty_size:ty, $x:expr) => {{
use core::fmt::Write;
let mut fstr0 = <$ty_size>::new();
let res = write!(&mut fstr0, "{}", $x);
fstr0
}};
}
#[macro_export]
macro_rules! convert_to_str {
($ty_size:ty, $x:expr) => {{
use core::fmt::Write;
let mut fstr0 = <$ty_size>::new();
let res = write!(&mut fstr0, "{}", $x);
if res.is_ok() {
Some(fstr0)
} else {
None
}
}};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn testmain() {
nostdtest();
ztests();
#[cfg(feature = "std")]
#[cfg(not(feature = "no-alloc"))]
maintest();
#[cfg(all(feature = "flex-str", feature = "std"))]
#[cfg(not(feature = "no-alloc"))]
flextest();
#[cfg(feature = "std")]
#[cfg(not(feature = "no-alloc"))]
tinytests();
#[cfg(all(feature = "std", feature = "flex-str"))]
#[cfg(not(feature = "no-alloc"))]
poppingtest();
#[cfg(all(feature = "std", feature = "shared-str"))]
#[cfg(not(feature = "no-alloc"))]
strptrtests();
#[cfg(feature = "pub-tstr")]
consttests();
}
#[cfg(feature = "std")]
#[cfg(feature = "shared-str")]
#[cfg(not(feature = "no-alloc"))]
fn strptrtests() {
extern crate std;
use std::fmt::Write;
use std::string::String;
let mut a = Sharedstr::<8>::from("abc12");
let mut b = a.clone();
let mut c = Sharedstr::<8>::from("abc");
c.push_str("12");
assert!(a == c);
assert!(a == "abc12");
b.push('3');
assert!(a == "abc123");
assert!("abc123" == b);
}
struct AB(i32, u32);
impl core::fmt::Display for AB {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{},{}", self.0, self.1)
}
}
#[cfg(all(feature = "std", feature = "flex-str"))]
#[cfg(not(feature = "no-alloc"))]
fn poppingtest() {
extern crate std;
use std::println;
let mut a = Flexstr::<8>::from("abcdef");
assert_eq!(a.pop_char().unwrap(), 'f');
println!("a: {}", &a);
let a = flexstr16::from("abcd");
let c: flexstr16 = &a + "efg";
assert_eq!(&c, "abcdefg");
let mut ab = AB(-5, 22 + 1);
let abfs = to_fixedstr!(zstr<16>, &ab);
assert_eq!(&abfs, "-5,23");
let abfs2 = convert_to_str!(zstr<3>, 10003);
assert!(abfs2.is_none());
}
fn nostdtest() {
let a: str8 = str8::from("abcdef"); let a2 = a; let ab = a.substr(1, 5); assert_eq!(ab, "bcde"); assert_eq!(&a[..3], "abc"); assert!(a < ab); let astr: &str = a.to_str(); let azstr: zstr<16> = zstr::from(a); let mut a32: str32 = a.resize(); a32 = "abc" + a32;
let mut u = str8::from("aλb"); assert_eq!(u.nth(1), Some('λ')); assert_eq!(u.nth_bytechar(3), 'b'); assert!(u.set(1, 'μ')); assert!(!u.set(1, 'c')); assert!(u.set(2, 'c'));
assert_eq!(u, "aμc");
assert_eq!(u.len(), 4); assert_eq!(u.charlen(), 3); let mut ac: str16 = a.reallocate().unwrap(); let remainder = ac.push_str("ghijklmnopq"); assert_eq!(ac.len(), 15);
assert_eq!(remainder, "pq");
ac.truncate(9); assert_eq!(&ac, "abcdefghi");
let (upper, lower) = (str8::make("ABC"), str8::make("abc"));
assert_eq!(upper, lower.to_ascii_upper());
let c1 = str8::from("abcd"); let c2 = str8::from("xyz");
assert!(c2.case_insensitive_eq("XyZ"));
let c2b = str16::from("xYz");
assert!(c2.case_insensitive_eq(&c2b));
let mut c3 = c1 + c2;
assert_eq!(c3, "abcdxyz");
assert_eq!(c3.capacity(), 15); c3 = "00" + c3 + "."; assert_eq!(c3, "00abcdxyz.");
let c4 = str_format!(str16, "abc {}{}{}", 1, 2, 3); assert_eq!(c4, "abc 123"); let c5 = try_format!(str8, "abcdef{}", "ghijklmn");
assert!(c5.is_none());
let fs = to_fixedstr!(str8, -0132);
assert_eq!(&fs, "-132");
const C:str16 = str16::const_make("abcd");
let xarray = [0u8;C.len()];
assert_eq!(C,"abcd");
assert_eq!(xarray.len(),4);
#[cfg(feature = "circular-str")]
{
use crate::circular_string::*;
let mut cb = cstr::<16>::make("abc123");
assert!(cb.is_contiguous());
cb.push_str("xyz");
cb.push_front("9876");
assert_eq!(cb.pop_char().unwrap(), 'z');
assert_eq!(cb.pop_char_front().unwrap(), '9');
cb.push_str_front("000");
assert_eq!(cb.len(), 14);
assert!(&cb == "000876abc123xy");
cb.truncate_left(10);
assert_eq!(&cb, "23xy");
cb.push_str("ijklmno ");
cb.push_char_front(' ');
assert!(&cb == " 23xyijklmno ");
assert!(!cb.is_contiguous());
cb.trim_whitespaces();
assert!("23xyijklmno" == &cb);
assert!(&cb < "4abc");
let mut a = cstr::<8>::make("12345678");
assert_eq!(a.len(), 8);
a.truncate_front(4);
assert_eq!(a.len(), 4);
assert!(a.is_contiguous());
assert!(&a == "5678");
a.push_str("abc");
assert!(&a == "5678abc");
let mut findopt = a.find_substr("8abc");
assert_eq!(findopt.unwrap(), 3);
findopt = a.rfind_substr("678abc");
assert_eq!(findopt.unwrap(), 1);
let mut rem = a.push_str("123456");
assert_eq!(rem, "23456");
a.truncate_left(4);
assert_eq!(&a, "abc1");
rem = a.push_front("qrstuvw");
assert_eq!(&a, "tuvwabc1");
assert_eq!(rem, "qrs");
rem = a.push_str("");
assert_eq!(&a, "tuvwabc1");
assert_eq!(rem, "");
a.truncate(5);
let mut ba = "123" + a;
assert_eq!(ba, "123tuvwa");
ba.truncate_left(4);
a.truncate_left(1);
assert_eq!(a, ba);
#[cfg(feature = "std")]
{
let bb = cstr::<8>::from("qgg");
extern crate std;
use std::collections::HashSet;
let mut hh = HashSet::new();
hh.insert(bb);
assert!(hh.get(&bb).is_some());
}
} }
fn ztests() {
let a: zstr<8> = zstr::from("abcdefg"); let ab = a.substr(1, 5); assert_eq!(ab, "bcde"); assert!(ab.case_insensitive_eq("bCdE"));
let mut u: zstr<8> = zstr::from("aλb"); assert!(u.set(1, 'μ')); assert!(!u.set(1, 'c')); assert!(u.set(2, 'c'));
assert_eq!(u, "aμc");
assert_eq!(u.len(), 4); assert_eq!(u.charlen(), 3); let mut ac: zstr<16> = a.resize(); let remainder = ac.push("hijklmnopqrst"); assert_eq!(ac.len(), 15);
assert_eq!(remainder, "pqrst");
ac.truncate(10);
assert_eq!(&ac, "abcdefghij");
assert_eq!(ac.len(), 10);
ac.pop_char();
ac.pop_char();
assert_eq!(ac.len(), 8);
let mut c4 = str_format!(zstr<16>, "abc {}", 123);
assert_eq!(c4, "abc 123");
let rem = c4.push_str("123456789abcdef");
assert_eq!(c4, "abc 12312345678");
assert_eq!(rem, "9abcdef");
let b = [65u8, 66, 67, 0, 0, 68, 0, 69, 0, 70, 0, 71];
let mut bz: zstr<16> = zstr::from_raw(&b);
bz.push("abcd \t \n\n");
bz.right_ascii_trim();
bz.reverse_bytes();
bz.make_ascii_lowercase();
}
#[cfg(feature = "std")]
#[cfg(not(feature = "no-alloc"))]
fn maintest() {
extern crate std;
use std::fmt::Write;
use std::println;
use std::string::String;
let s1: fstr<16> = fstr::from("abc");
let mut s2: fstr<8> = fstr::from("and xyz");
let s2r = s2.push(" and 1234");
println!("s1,s2,s2r,s2.len: {}, {}, {}, {}", s1, &s2, &s2r, s2.len());
println!("{}", &s1 == "abc");
let s3 = s1; println!("{}", "abc" == &s1);
println!("{}, {} ", s1 == s3, s1 == s2.resize());
let mut s4: fstr<256> = s3.resize();
s4.push("ccccccccccccccccccccccccccccccccccccccccccccccccccccccz");
println!("{}, length {}", &s4, s4.len());
let mut s5: fstr<32> = s4.resize();
println!("{}, length {}", &s5, s5.len());
println!("{:?}, length {}", &s5[0..10], s5.len());
println!("s2.substr {}", s2.substr(2, 6));
println!("{}", s2.substr(2, 6).len());
let mut s4: fstr<64> = s1.resize();
let owned_string: String = s4.to_string();
println!("owned s4: {}", &owned_string);
let str_slice: &str = s4.to_str();
println!("as &str: {}", &str_slice[0..2]);
s4 = s1.resize();
let s5 = fstr::<8>::new();
let ss5 = s5.as_str();
let mut s6 = fstr::<32>::new();
let result = write!(&mut s6, "hello {}, {}, {}", 1, 2, 3);
assert_eq!(s6, "hello 1, 2, 3");
println!("s6 is {}, result is {:?}", &s6, &result);
let s7 = str_format!(fstr<32>, "abc {}, {}", 1, 10);
println!("s7 is {}", &s7);
let s8 = try_format!(fstr<32>, "abcdefg {}, {}", 1, 10);
println!("s8 is {}", &s8.unwrap());
let mut f1 = fstr::<16>::from("abcdefg");
let f2 = f1.to_ascii_uppercase();
#[cfg(feature = "experimental")]
{
let mut s = <zstr<8>>::from("abcd");
s[0] = b'A'; assert_eq!('A', s.nth_ascii(0));
}
use std::collections::HashMap;
let mut hm = HashMap::new();
hm.insert(str8::from("abc"), 1);
assert!(hm.contains_key(&str8::from("abc")));
let mut a: fstr<8> = fstr::from("abcdef");
let rem = a.push("g");
assert!(rem == "" && &a == "abcdefg");
ftests();
}
#[cfg(feature = "std")]
#[cfg(not(feature = "no-alloc"))]
fn ftests() {
extern crate std;
use std::{println, string::String, format};
let a: fstr<8> = fstr::from("abcdefg"); let a1: fstr<8> = a; let a2: &str = a.to_str();
let a3: String = a.to_string();
assert_eq!(a.nth_ascii(2), 'c');
let ab = a.substr(1, 5); assert!(ab == "bcde" && a1 == a); assert!(a < ab); let mut u: fstr<8> = fstr::from("aλb"); u.nth(1).map(|x| assert_eq!(x, 'λ')); assert!(u.set(1, 'μ')); assert!(!u.set(1, 'c')); assert!(u.set(2, 'c'));
assert_eq!(u, "aμc");
assert_eq!(u.len(), 4); assert_eq!(u.charlen(), 3); let mut ac: fstr<16> = a.resize(); let remainder: &str = ac.push("hijklmnopqrst"); assert_eq!(ac.len(), 16);
assert_eq!(remainder, "qrst");
ac.truncate(10); assert_eq!(&ac, "abcdefghij");
println!("ac {}, remainder: {}", &ac, &remainder);
assert_eq!(ac.pop_char().unwrap(), 'j');
assert_eq!(ac, "abcdefghi");
let ac2: fstr<16> = fstr::make("abcd");
ac.truncate(4);
assert_eq!(ac, ac2);
let mut z8 = zstr::<16>::from("abc12");
let z8o = str_format!(zstr<16>,"xxx {}3",z8);
assert_eq!(z8o, "xxx abc123");
let zoo = format!("xx{}yy",z8o);
assert_eq!(zoo,"xxxxx abc123yy");
}
#[cfg(all(feature = "std", feature = "flex-str"))]
#[cfg(not(feature = "no-alloc"))]
fn flextest() {
extern crate std;
use std::fmt::Write;
use std::println;
use std::string::String;
println!("starting Flexstr tests...");
let mut a: Flexstr<8> = Flexstr::from("abcdef");
a.truncate(5);
assert_eq!(a, "abcde"); assert_eq!(&a[..3], "abc"); println!("Flexstr slice: {}", &a[1..4]);
let ab = Flexstr::<8>::from("bcdefghijklmnop");
assert!(a.is_fixed());
assert!(!ab.is_fixed());
let a2: str8 = a.get_str().unwrap();
assert!(a < ab); let astr: &str = a.to_str(); let aowned: String = a.to_string(); let mut u = Flexstr::<8>::from("aλb"); assert_eq!(u.nth(1), Some('λ')); assert_eq!(u.nth_ascii(3), 'b'); assert!(u.set(1, 'μ')); assert!(!u.set(1, 'c')); assert!(u.set(2, 'c'));
assert_eq!(u, "aμc");
assert_eq!(u.len(), 4); assert_eq!(u.charlen(), 3); let mut v: Flexstr<4> = Flexstr::from("aμcxyz");
v.set(1, 'λ');
println!("v: {}", &v);
let mut u2: Flexstr<16> = u.resize();
u2.push_str("aaaaaaaa");
println!("{} len {}", &u2, u2.len());
assert!(u2.is_fixed());
let mut s: Flexstr<8> = Flexstr::from("abcdef");
assert!(s.is_fixed());
s.push_str("ghijk");
assert!(s.is_owned());
s.truncate(7);
assert!(s.is_fixed());
let ab = Flexstr::<32>::from("bcdefghijklmnop");
println!("size of ab: {}", std::mem::size_of::<Flexstr<32>>());
let mut vv = Flexstr::<8>::from("abcd");
vv.push('e');
println!("vv: {}", &vv);
vv.push_str("abcdefasdfasdfadfssfs");
let vvs = vv.split_off();
println!("vv: {}, vvs: {}", &vv, &vvs);
let mut fs: Flexstr<4> = Flexstr::from("abcdefg");
let extras = fs.split_off();
assert!(&fs == "abc" && &extras == "defg" && fs.is_fixed());
let fss = fs.to_string();
assert!(&fss == "abc");
}
#[cfg(feature = "std")]
#[cfg(not(feature = "no-alloc"))]
fn tinytests() {
extern crate std;
use std::fmt::Write;
use std::println;
use std::string::String;
println!("starting tstr tests...");
let a: str8 = str8::from("abcdef");
let a2 = a; let ab = a.substr(1, 5); assert_eq!(ab, "bcde"); assert_eq!(&a[..3], "abc"); assert_eq!(ab.len(), 4);
println!("str8: {}", &a);
assert!(a < ab); let astr: &str = a.to_str(); let aowned: String = a.to_string(); let afstr: fstr<8> = fstr::from(a); let azstr: zstr<16> = zstr::from(a); let a32: str32 = a.resize(); let mut u = str8::from("aλb"); assert_eq!(u.nth(1), Some('λ')); assert_eq!(u.nth_ascii(3), 'b'); assert!(u.set(1, 'μ')); assert!(!u.set(1, 'c')); assert!(u.set(2, 'c'));
assert_eq!(u, "aμc");
assert_eq!(u.len(), 4); assert_eq!(u.charlen(), 3); let mut ac: str16 = a.reallocate().unwrap(); let remainder = ac.push("ghijklmnopq"); assert_eq!(ac.len(), 15);
assert_eq!(remainder, "pq");
println!("ac {}, remainder: {}", &ac, &remainder);
ac.truncate(9); assert_eq!(&ac, "abcdefghi");
println!("ac {}, remainder: {}", &ac, &remainder);
let mut s = str8::from("aλc");
assert_eq!(s.capacity(), 7);
assert_eq!(s.push("1234567"), "4567");
assert_eq!(s, "aλc123");
assert_eq!(s.charlen(), 6); assert_eq!(s.len(), 7);
println!("size of str8: {}", std::mem::size_of::<str8>());
println!("size of zstr<8>: {}", std::mem::size_of::<zstr<8>>());
println!("size of &str: {}", std::mem::size_of::<&str>());
println!("size of &str8: {}", std::mem::size_of::<&str8>());
let mut toosmall: fstr<8> = fstr::make("abcdefghijkl");
let mut toosmallz: zstr<8> = zstr::make("abcdefghijkl");
let mut toosmallt: str8 = str8::make("abcdefghijkl");
println!("toosmall: {}", toosmall);
let waytoosmall: fstr<4> = toosmall.resize();
let way2: zstr<4> = toosmallz.resize();
let mut way3: str16 = str16::make("abcdefedefsfsdfsd");
let way4: str8 = way3.resize();
way3 = way4.resize();
println!("way3: {}, length {}", way3, way3.len());
let b: str8 = str8::from("abcdefg");
let mut b2: fstr<32> = fstr::from(b);
b2.push("hijklmnop");
println!("b2 is {}", &b2);
let mut b3: zstr<300> = zstr::from(b);
b3.push("hijklmnopqrstuvw");
println!("b3 is {}", &b3);
let mut b4 = str128::from(b2);
b4.push("xyz");
println!("b4 is {}", &b4);
let (upper, lower) = (str8::make("ABC"), str8::make("abc"));
assert_eq!(upper, lower.to_ascii_upper());
let c1 = str8::from("abcdef");
let c2 = str8::from("xyz123");
let c3 = c1 + c2 + "999";
assert_eq!(c3, "abcdefxyz123999");
assert_eq!(c3.capacity(), 15);
let c4 = str_format!(str16, "abc {}{}{}", 1, 2, 3);
assert_eq!(c4, "abc 123");
let c5 = try_format!(str8, "abc {}{}", &c1, &c2);
assert!(c5.is_none());
let s = try_format!(str32, "abcdefg{}", "hijklmnop").unwrap();
let s2 = try_format!(str8, "abcdefg{}", "hijklmnop");
assert!(s2.is_none());
let mut c4b = str16::from("abc 12345");
c4b.truncate(7);
assert_eq!(c4, c4b);
let zb = ztr8::from("abc");
let mut zc = ztr8::from("abcde");
zc.truncate(3);
assert_eq!(zb, zc);
}
#[cfg(feature = "pub-tstr")]
fn consttests() {
let ls = tstr::<{tstr_limit(258)}>::from("abcd");
assert_eq!(ls.capacity(),255);
}}