pub type TinyStr4 = TinyAsciiStr<4>;
Expand description
These are temporary compatability reexports that will be removed in a future version.
Aliased Type§
struct TinyStr4 { /* private fields */ }
Implementations
Source§impl<const N: usize> TinyAsciiStr<N>
impl<const N: usize> TinyAsciiStr<N>
pub const fn try_from_str(s: &str) -> Result<Self, ParseError>
Sourcepub const fn try_from_utf8(code_units: &[u8]) -> Result<Self, ParseError>
pub const fn try_from_utf8(code_units: &[u8]) -> Result<Self, ParseError>
Creates a TinyAsciiStr<N>
from the given UTF-8 slice.
code_units
may contain at most N
non-null ASCII code points.
Sourcepub const fn try_from_utf16(code_units: &[u16]) -> Result<Self, ParseError>
pub const fn try_from_utf16(code_units: &[u16]) -> Result<Self, ParseError>
Creates a TinyAsciiStr<N>
from the given UTF-16 slice.
code_units
may contain at most N
non-null ASCII code points.
Sourcepub const fn from_utf8_lossy(code_units: &[u8], replacement: u8) -> Self
pub const fn from_utf8_lossy(code_units: &[u8], replacement: u8) -> Self
Creates a TinyAsciiStr<N>
from a UTF-8 slice, replacing invalid code units.
Invalid code units, as well as null or non-ASCII code points (i.e. those outside the range U+0001..=U+007F`) will be replaced with the replacement byte.
The input slice will be truncated if its length exceeds N
.
Sourcepub const fn from_utf16_lossy(code_units: &[u16], replacement: u8) -> Self
pub const fn from_utf16_lossy(code_units: &[u16], replacement: u8) -> Self
Creates a TinyAsciiStr<N>
from a UTF-16 slice, replacing invalid code units.
Invalid code units, as well as null or non-ASCII code points (i.e. those outside the range U+0001..=U+007F`) will be replaced with the replacement byte.
The input slice will be truncated if its length exceeds N
.
Sourcepub const fn try_from_raw(raw: [u8; N]) -> Result<Self, ParseError>
pub const fn try_from_raw(raw: [u8; N]) -> Result<Self, ParseError>
Attempts to parse a fixed-length byte array to a TinyAsciiStr
.
The byte array may contain trailing NUL bytes.
§Example
use tinystr::tinystr;
use tinystr::TinyAsciiStr;
assert_eq!(
TinyAsciiStr::<3>::try_from_raw(*b"GB\0"),
Ok(tinystr!(3, "GB"))
);
assert_eq!(
TinyAsciiStr::<3>::try_from_raw(*b"USD"),
Ok(tinystr!(3, "USD"))
);
assert!(matches!(TinyAsciiStr::<3>::try_from_raw(*b"\0A\0"), Err(_)));
pub const fn as_str(&self) -> &str
pub const fn len(&self) -> usize
pub const fn is_empty(&self) -> bool
pub const fn as_utf8(&self) -> &[u8] ⓘ
pub const fn all_bytes(&self) -> &[u8; N]
Sourcepub const fn resize<const M: usize>(self) -> TinyAsciiStr<M>
pub const fn resize<const M: usize>(self) -> TinyAsciiStr<M>
Resizes a TinyAsciiStr<N>
to a TinyAsciiStr<M>
.
If M < len()
the string gets truncated, otherwise only the
memory representation changes.
Sourcepub const fn concat<const M: usize, const Q: usize>(
self,
other: TinyAsciiStr<M>,
) -> TinyAsciiStr<Q>
pub const fn concat<const M: usize, const Q: usize>( self, other: TinyAsciiStr<M>, ) -> TinyAsciiStr<Q>
Returns a TinyAsciiStr<Q>
with the concatenation of this string,
TinyAsciiStr<N>
, and another string, TinyAsciiStr<M>
.
If Q < N + M
, the string gets truncated.
§Examples
use tinystr::tinystr;
use tinystr::TinyAsciiStr;
let abc = tinystr!(6, "abc");
let defg = tinystr!(6, "defg");
// The concatenation is successful if Q is large enough...
assert_eq!(abc.concat(defg), tinystr!(16, "abcdefg"));
assert_eq!(abc.concat(defg), tinystr!(12, "abcdefg"));
assert_eq!(abc.concat(defg), tinystr!(8, "abcdefg"));
assert_eq!(abc.concat(defg), tinystr!(7, "abcdefg"));
/// ...but it truncates of Q is too small.
assert_eq!(abc.concat(defg), tinystr!(6, "abcdef"));
assert_eq!(abc.concat(defg), tinystr!(2, "ab"));
Sourcepub const unsafe fn from_utf8_unchecked(code_units: [u8; N]) -> Self
pub const unsafe fn from_utf8_unchecked(code_units: [u8; N]) -> Self
§Safety
Must be called with a bytes array made of valid ASCII bytes, with no null bytes between ASCII characters
Source§impl<const N: usize> TinyAsciiStr<N>
impl<const N: usize> TinyAsciiStr<N>
Sourcepub const fn is_ascii_alphabetic(&self) -> bool
pub const fn is_ascii_alphabetic(&self) -> bool
Checks if the value is composed of ASCII alphabetic characters:
- U+0041 ‘A’ ..= U+005A ‘Z’, or
- U+0061 ‘a’ ..= U+007A ‘z’.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "Test".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "Te3t".parse().expect("Failed to parse.");
assert!(s1.is_ascii_alphabetic());
assert!(!s2.is_ascii_alphabetic());
Sourcepub const fn is_ascii_alphanumeric(&self) -> bool
pub const fn is_ascii_alphanumeric(&self) -> bool
Checks if the value is composed of ASCII alphanumeric characters:
- U+0041 ‘A’ ..= U+005A ‘Z’, or
- U+0061 ‘a’ ..= U+007A ‘z’, or
- U+0030 ‘0’ ..= U+0039 ‘9’.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "A15b".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "[3@w".parse().expect("Failed to parse.");
assert!(s1.is_ascii_alphanumeric());
assert!(!s2.is_ascii_alphanumeric());
Sourcepub const fn is_ascii_numeric(&self) -> bool
pub const fn is_ascii_numeric(&self) -> bool
Checks if the value is composed of ASCII decimal digits:
- U+0030 ‘0’ ..= U+0039 ‘9’.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "312".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "3d".parse().expect("Failed to parse.");
assert!(s1.is_ascii_numeric());
assert!(!s2.is_ascii_numeric());
Sourcepub const fn is_ascii_lowercase(&self) -> bool
pub const fn is_ascii_lowercase(&self) -> bool
Checks if the value is in ASCII lower case.
All letter characters are checked for case. Non-letter characters are ignored.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "teSt".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "test".parse().expect("Failed to parse.");
let s3: TinyAsciiStr<4> = "001z".parse().expect("Failed to parse.");
assert!(!s1.is_ascii_lowercase());
assert!(s2.is_ascii_lowercase());
assert!(s3.is_ascii_lowercase());
Sourcepub const fn is_ascii_titlecase(&self) -> bool
pub const fn is_ascii_titlecase(&self) -> bool
Checks if the value is in ASCII title case.
This verifies that the first character is ASCII uppercase and all others ASCII lowercase. Non-letter characters are ignored.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "teSt".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "Test".parse().expect("Failed to parse.");
let s3: TinyAsciiStr<4> = "001z".parse().expect("Failed to parse.");
assert!(!s1.is_ascii_titlecase());
assert!(s2.is_ascii_titlecase());
assert!(s3.is_ascii_titlecase());
Sourcepub const fn is_ascii_uppercase(&self) -> bool
pub const fn is_ascii_uppercase(&self) -> bool
Checks if the value is in ASCII upper case.
All letter characters are checked for case. Non-letter characters are ignored.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "teSt".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "TEST".parse().expect("Failed to parse.");
let s3: TinyAsciiStr<4> = "001z".parse().expect("Failed to parse.");
assert!(!s1.is_ascii_uppercase());
assert!(s2.is_ascii_uppercase());
assert!(!s3.is_ascii_uppercase());
Sourcepub const fn is_ascii_alphabetic_lowercase(&self) -> bool
pub const fn is_ascii_alphabetic_lowercase(&self) -> bool
Checks if the value is composed of ASCII alphabetic lower case characters:
- U+0061 ‘a’ ..= U+007A ‘z’,
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "Test".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "Te3t".parse().expect("Failed to parse.");
let s3: TinyAsciiStr<4> = "teSt".parse().expect("Failed to parse.");
let s4: TinyAsciiStr<4> = "test".parse().expect("Failed to parse.");
let s5: TinyAsciiStr<4> = "001z".parse().expect("Failed to parse.");
assert!(!s1.is_ascii_alphabetic_lowercase());
assert!(!s2.is_ascii_alphabetic_lowercase());
assert!(!s3.is_ascii_alphabetic_lowercase());
assert!(s4.is_ascii_alphabetic_lowercase());
assert!(!s5.is_ascii_alphabetic_lowercase());
Sourcepub const fn is_ascii_alphabetic_titlecase(&self) -> bool
pub const fn is_ascii_alphabetic_titlecase(&self) -> bool
Checks if the value is composed of ASCII alphabetic, with the first character being ASCII uppercase, and all others ASCII lowercase.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "Test".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "Te3t".parse().expect("Failed to parse.");
let s3: TinyAsciiStr<4> = "teSt".parse().expect("Failed to parse.");
let s4: TinyAsciiStr<4> = "test".parse().expect("Failed to parse.");
let s5: TinyAsciiStr<4> = "001z".parse().expect("Failed to parse.");
assert!(s1.is_ascii_alphabetic_titlecase());
assert!(!s2.is_ascii_alphabetic_titlecase());
assert!(!s3.is_ascii_alphabetic_titlecase());
assert!(!s4.is_ascii_alphabetic_titlecase());
assert!(!s5.is_ascii_alphabetic_titlecase());
Sourcepub const fn is_ascii_alphabetic_uppercase(&self) -> bool
pub const fn is_ascii_alphabetic_uppercase(&self) -> bool
Checks if the value is composed of ASCII alphabetic upper case characters:
- U+0041 ‘A’ ..= U+005A ‘Z’,
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "Test".parse().expect("Failed to parse.");
let s2: TinyAsciiStr<4> = "Te3t".parse().expect("Failed to parse.");
let s3: TinyAsciiStr<4> = "teSt".parse().expect("Failed to parse.");
let s4: TinyAsciiStr<4> = "TEST".parse().expect("Failed to parse.");
let s5: TinyAsciiStr<4> = "001z".parse().expect("Failed to parse.");
assert!(!s1.is_ascii_alphabetic_uppercase());
assert!(!s2.is_ascii_alphabetic_uppercase());
assert!(!s3.is_ascii_alphabetic_uppercase());
assert!(s4.is_ascii_alphabetic_uppercase());
assert!(!s5.is_ascii_alphabetic_uppercase());
Source§impl<const N: usize> TinyAsciiStr<N>
impl<const N: usize> TinyAsciiStr<N>
Sourcepub const fn to_ascii_lowercase(self) -> Self
pub const fn to_ascii_lowercase(self) -> Self
Converts this type to its ASCII lower case equivalent in-place.
ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, other characters are unchanged.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "TeS3".parse().expect("Failed to parse.");
assert_eq!(&*s1.to_ascii_lowercase(), "tes3");
Sourcepub const fn to_ascii_titlecase(self) -> Self
pub const fn to_ascii_titlecase(self) -> Self
Converts this type to its ASCII title case equivalent in-place.
The first character is converted to ASCII uppercase; the remaining characters are converted to ASCII lowercase.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "teSt".parse().expect("Failed to parse.");
assert_eq!(&*s1.to_ascii_titlecase(), "Test");
Sourcepub const fn to_ascii_uppercase(self) -> Self
pub const fn to_ascii_uppercase(self) -> Self
Converts this type to its ASCII upper case equivalent in-place.
ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, other characters are unchanged.
§Examples
use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "Tes3".parse().expect("Failed to parse.");
assert_eq!(&*s1.to_ascii_uppercase(), "TES3");
Source§impl<const N: usize> TinyAsciiStr<N>
impl<const N: usize> TinyAsciiStr<N>
pub const fn to_unvalidated(self) -> UnvalidatedTinyAsciiStr<N>
Trait Implementations
Source§impl<const N: usize> AsULE for TinyAsciiStr<N>
impl<const N: usize> AsULE for TinyAsciiStr<N>
Source§type ULE = TinyAsciiStr<N>
type ULE = TinyAsciiStr<N>
Self
. Read moreSource§fn to_unaligned(self) -> Self::ULE
fn to_unaligned(self) -> Self::ULE
Source§fn from_unaligned(unaligned: Self::ULE) -> Self
fn from_unaligned(unaligned: Self::ULE) -> Self
Source§impl<const N: usize> Bake for TinyAsciiStr<N>
impl<const N: usize> Bake for TinyAsciiStr<N>
Source§fn bake(&self, env: &CrateEnv) -> TokenStream
fn bake(&self, env: &CrateEnv) -> TokenStream
Source§impl<const N: usize> BakeSize for TinyAsciiStr<N>
impl<const N: usize> BakeSize for TinyAsciiStr<N>
Source§fn borrows_size(&self) -> usize
fn borrows_size(&self) -> usize
Source§impl<const N: usize> Clone for TinyAsciiStr<N>
impl<const N: usize> Clone for TinyAsciiStr<N>
Source§fn clone(&self) -> TinyAsciiStr<N>
fn clone(&self) -> TinyAsciiStr<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<const N: usize> Debug for TinyAsciiStr<N>
impl<const N: usize> Debug for TinyAsciiStr<N>
Source§impl<const N: usize> Deref for TinyAsciiStr<N>
impl<const N: usize> Deref for TinyAsciiStr<N>
Source§impl<'de, const N: usize> Deserialize<'de> for TinyAsciiStr<N>
impl<'de, const N: usize> Deserialize<'de> for TinyAsciiStr<N>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<const N: usize> Display for TinyAsciiStr<N>
impl<const N: usize> Display for TinyAsciiStr<N>
Source§impl<const N: usize> FromStr for TinyAsciiStr<N>
impl<const N: usize> FromStr for TinyAsciiStr<N>
Source§impl<const N: usize> Hash for TinyAsciiStr<N>
impl<const N: usize> Hash for TinyAsciiStr<N>
Source§impl<const N: usize> NicheBytes<N> for TinyAsciiStr<N>
impl<const N: usize> NicheBytes<N> for TinyAsciiStr<N>
const NICHE_BIT_PATTERN: [u8; N]
Source§impl<const N: usize> Ord for TinyAsciiStr<N>
impl<const N: usize> Ord for TinyAsciiStr<N>
Source§fn cmp(&self, other: &TinyAsciiStr<N>) -> Ordering
fn cmp(&self, other: &TinyAsciiStr<N>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const N: usize> PartialEq for TinyAsciiStr<N>
impl<const N: usize> PartialEq for TinyAsciiStr<N>
Source§impl<const N: usize> PartialOrd for TinyAsciiStr<N>
impl<const N: usize> PartialOrd for TinyAsciiStr<N>
Source§impl<const N: usize> Serialize for TinyAsciiStr<N>
impl<const N: usize> Serialize for TinyAsciiStr<N>
Source§impl<const N: usize> ULE for TinyAsciiStr<N>
impl<const N: usize> ULE for TinyAsciiStr<N>
Source§fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>
fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>
&[u8]
. Read more§fn parse_bytes_to_slice(bytes: &[u8]) -> Result<&[Self], UleError>
fn parse_bytes_to_slice(bytes: &[u8]) -> Result<&[Self], UleError>
§unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
&[u8]
, and return it as &[Self]
with the same lifetime, assuming
that this byte slice has previously been run through [Self::parse_bytes_to_slice()
] with
success. Read more§fn slice_as_bytes(slice: &[Self]) -> &[u8] ⓘ
fn slice_as_bytes(slice: &[Self]) -> &[u8] ⓘ
Source§impl<'a, const N: usize> ZeroMapKV<'a> for TinyAsciiStr<N>
impl<'a, const N: usize> ZeroMapKV<'a> for TinyAsciiStr<N>
Source§type Container = ZeroVec<'a, TinyAsciiStr<N>>
type Container = ZeroVec<'a, TinyAsciiStr<N>>
ZeroVec
] or [VarZeroVec
].type Slice = ZeroSlice<TinyAsciiStr<N>>
Source§type GetType = TinyAsciiStr<N>
type GetType = TinyAsciiStr<N>
Container::get()
Read moreSource§type OwnedType = TinyAsciiStr<N>
type OwnedType = TinyAsciiStr<N>
Container::replace()
and Container::remove()
,
also used during deserialization. If Self
is human readable serialized,
deserializing to Self::OwnedType
should produce the same value once
passed through Self::owned_as_self()
Read more