tinystr

Type Alias TinyStr4

Source
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>

Source

pub const fn from_bytes(bytes: &[u8]) -> Result<Self, TinyStrError>

Creates a TinyAsciiStr<N> from the given byte slice. bytes may contain at most N non-null ASCII bytes.

Source

pub const fn from_bytes_lossy(bytes: &[u8]) -> Self

Creates a TinyAsciiStr<N> from a byte slice, replacing invalid bytes.

Null and non-ASCII bytes (i.e. those outside the range 0x01..=0x7F) will be replaced with the ‘?’ character.

The input slice will be truncated if its length exceeds N.

Source

pub const fn try_from_raw(raw: [u8; N]) -> Result<Self, TinyStrError>

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 from_bytes_manual_slice( bytes: &[u8], start: usize, end: usize, ) -> Result<Self, TinyStrError>

Equivalent to from_bytes(bytes[start..end]), but callable in a const context (which range indexing is not).

Source

pub const fn from_str(s: &str) -> Result<Self, TinyStrError>

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_bytes(&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 unsafe fn from_bytes_unchecked(bytes: [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> 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<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 = TinyStrError

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> 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> ULE for TinyAsciiStr<N>

Source§

fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>

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

fn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>

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

unsafe fn from_byte_slice_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_byte_slice() with success. Read more
Source§

fn as_byte_slice(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>