tinystr

Type Alias TinyStr16

Source
pub type TinyStr16 = TinyAsciiStr<16>;
Expand description

These are temporary compatability reexports that will be removed in a future version.

Aliased Type§

struct TinyStr16 { /* private fields */ }

Implementations

Source§

impl<const N: usize> TinyAsciiStr<N>

Source

pub const fn try_from_str(s: &str) -> Result<Self, ParseError>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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(_)));
Source

pub const fn as_str(&self) -> &str

Source

pub const fn len(&self) -> usize

Source

pub const fn is_empty(&self) -> bool

Source

pub const fn as_utf8(&self) -> &[u8]

Source

pub const fn all_bytes(&self) -> &[u8; N]

Source

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.

Source

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"));
Source

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>

Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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>

Source

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");
Source

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");
Source

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>

Trait Implementations

Source§

impl<const N: usize> AsULE for TinyAsciiStr<N>

Source§

type ULE = TinyAsciiStr<N>

The ULE type corresponding to Self. Read more
Source§

fn to_unaligned(self) -> Self::ULE

Converts from Self to Self::ULE. Read more
Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Converts from Self::ULE to Self. Read more
Source§

impl<const N: usize> Bake for TinyAsciiStr<N>

Source§

fn bake(&self, env: &CrateEnv) -> TokenStream

Returns a TokenStream that would evaluate to self. Read more
Source§

impl<const N: usize> BakeSize for TinyAsciiStr<N>

Source§

fn borrows_size(&self) -> usize

Returns the size
Source§

impl<const N: usize> Borrow<str> for TinyAsciiStr<N>

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl<const N: usize> Clone for TinyAsciiStr<N>

Source§

fn clone(&self) -> TinyAsciiStr<N>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for TinyAsciiStr<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Deref for TinyAsciiStr<N>

Source§

type Target = str

The resulting type after dereferencing.
Source§

fn deref(&self) -> &str

Dereferences the value.
Source§

impl<'de, const N: usize> Deserialize<'de> for TinyAsciiStr<N>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const N: usize> Display for TinyAsciiStr<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> FromStr for TinyAsciiStr<N>

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<const N: usize> Hash for TinyAsciiStr<N>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: usize> NicheBytes<N> for TinyAsciiStr<N>

Source§

impl<const N: usize> Ord for TinyAsciiStr<N>

Source§

fn cmp(&self, other: &TinyAsciiStr<N>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const N: usize> PartialEq<&str> for TinyAsciiStr<N>

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq<String> for TinyAsciiStr<N>

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq<str> for TinyAsciiStr<N>

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq for TinyAsciiStr<N>

Source§

fn eq(&self, other: &TinyAsciiStr<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialOrd for TinyAsciiStr<N>

Source§

fn partial_cmp(&self, other: &TinyAsciiStr<N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: usize> Serialize for TinyAsciiStr<N>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const N: usize> ULE for TinyAsciiStr<N>

Source§

fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>

Validates a byte slice, &[u8]. Read more
§

fn parse_bytes_to_slice(bytes: &[u8]) -> Result<&[Self], UleError>

Parses a byte slice, &[u8], and return it as &[Self] with the same lifetime. Read more
§

unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]

Takes a byte slice, &[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]

Given &[Self], returns a &[u8] with the same lifetime. Read more
Source§

impl<'a, const N: usize> ZeroMapKV<'a> for TinyAsciiStr<N>

Source§

type Container = ZeroVec<'a, TinyAsciiStr<N>>

The container that can be used with this type: [ZeroVec] or [VarZeroVec].
Source§

type Slice = ZeroSlice<TinyAsciiStr<N>>

Source§

type GetType = TinyAsciiStr<N>

The type produced by Container::get() Read more
Source§

type OwnedType = TinyAsciiStr<N>

The type produced by 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
Source§

impl<const N: usize> Copy for TinyAsciiStr<N>

Source§

impl<const N: usize> Eq for TinyAsciiStr<N>

Source§

impl<const N: usize> StructuralPartialEq for TinyAsciiStr<N>