Struct PascalString

Source
pub struct PascalString { /* private fields */ }
Expand description

An owned PascalString. This string type stores its data the stack. It is always 256 bytes long, with the first byte storing the length.

This string type uses Ascii encoding.

Implementations§

Source§

impl PascalString

Source

pub fn new() -> Self

Creates a new, empty PascalString.

Source

pub fn from_fixed_ascii_array<C>( string_len: u8, char_array: [C; 255], ) -> Result<Self, PascalStringCreateError>
where C: ToAsciiChar + Clone,

Create a new PascalString from its constituent parts: string_len and char_array.

Returns an Err if char_array is not valid Ascii.

Source

pub fn from<B: AsRef<[u8]>>(bytes: B) -> Result<Self, PascalStringCreateError>

Create a new PascalString using the contents of bytes.

Returns an Err if bytes is longer than 255 characters, or it does not contain Ascii encoded characters.

Source

pub fn push<C: ToAsciiChar>(&mut self, character: C)

Push an ascii convertible character onto this string.

§Panics

Panics if the string is full, of if the character is not a valid ascii character.

Source

pub fn try_push<C: ToAsciiChar>( &mut self, character: C, ) -> Result<(), PascalStringAppendError>

Attempt to push an ascii convertible character onto the end of this PascalString.

Returns Err(_) if the character cannot be pushed because this PascalString is full, or if character is not a valid ascii character.

Source

pub fn push_str<S: AsRef<str>>(&mut self, s: S)

Append a given string slice onto the end of this PascalString.

§Panics

Panics if the string cannot be pushed to because this PascalString is full.

Source

pub fn try_push_str<S: AsRef<str>>( &mut self, s: S, ) -> Result<(), PascalStringAppendError>

Attempt to append a given string slice onto the end of this PascalString.

Returns Err(_) if the string cannot be pushed because this PascalString is full.

Source

pub fn pop(&mut self) -> Option<AsciiChar>

Removes the last character from the string buffer and returns it.

Returns None if this PascalString is empty.

Source

pub fn remove(&mut self, index: u8) -> AsciiChar

Remove a character from the AsciiString at index.

§Panics

Panics if index is larger than self.len(), or if self.is_empty() is true.

Source

pub fn insert<C: ToAsciiChar>(&mut self, ch: C, index: u8)

Insert a character into the AsciiString at index.

§Panics

Panics if index is larger than self.len(), or if the PascalString is full.

Source

pub fn clear(&mut self)

Truncates this String, removing all contents.

Does not zero the values of the string.

Source

pub fn to_array(self) -> [u8; 256]

Consumes this PascalString, and returns its inner state as a [u8; 256], where the first byte is the length.

Note that if the string has been truncated, bytes beyond the end of the string will not have been zeroed.

Methods from Deref<Target = PascalStr>§

Source

pub fn as_ptr(&self) -> *const AsciiChar

Get a pointer to the first byte of the string buffer.

Source

pub fn as_mut_ptr(&mut self) -> *mut AsciiChar

Get a mutable pointer to the first byte of the string buffer.

Source

pub fn as_str(&self) -> &str

Get the PascalStr as an immutable &str reference.

Source

pub fn as_cstr(&self) -> Result<Cow<'_, CStr>, InteriorNullError>

Get this string as a CStr.

Returns Err(InteriorNullError) if the string contains any interior nulls. If this string is full, then a new CString will be allocated to hold the trailing null byte.

Source

pub fn len(&self) -> usize

Returns the number of characters used in the string.

Source

pub fn is_empty(&self) -> bool

Returns true if the string has a length of 0

Source

pub fn is_full(&self) -> bool

Returns true if the string has a length of 255.

When this value is true, no more elements can be pushed onto the string.

Source

pub fn chars<'a>(&'a self) -> Chars<'a>

Get an immutable iterator to the internal character array.

Source

pub fn chars_mut<'a>(&'a mut self) -> CharsMut<'a>

Get a mutable iterator to the internal character array.

Source

pub fn lines(&self) -> Lines<'_>

Get an iterator over the lines of the internal character array.

Source

pub fn get_unchecked(&self, index: usize) -> AsciiChar

Get a character in the string, without checking if the index is within the bounds of len().

This method cannot cause memory unsafety because index is bounds checked within the maximum possible length of the PascalStr, which means that it cannot read uninitialised memory. However, it can give access to stale characters if index is greater than or equal to self.len() or isize::MAX, and self.is_full() is false.

§Panics

This method will panic if index is larger than u8::MAX(255).

Trait Implementations§

Source§

impl AsMut<[AsciiChar]> for PascalString

Source§

fn as_mut(&mut self) -> &mut [AsciiChar]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<[AsciiChar]> for PascalString

Source§

fn as_ref(&self) -> &[AsciiChar]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<[u8]> for PascalString

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<AsciiStr> for PascalString

Source§

fn as_ref(&self) -> &AsciiStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<PascalStr> for PascalString

Source§

fn as_ref(&self) -> &PascalStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for PascalString

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsciiExt for PascalString

Source§

type Owned = PascalString

👎Deprecated since 1.26.0: use inherent methods instead
Container type for copied ASCII characters.
Source§

fn is_ascii(&self) -> bool

👎Deprecated since 1.26.0: use inherent methods instead
Checks if the value is within the ASCII range. Read more
Source§

fn to_ascii_uppercase(&self) -> Self::Owned

👎Deprecated since 1.26.0: use inherent methods instead
Makes a copy of the value in its ASCII upper case equivalent. Read more
Source§

fn to_ascii_lowercase(&self) -> Self::Owned

👎Deprecated since 1.26.0: use inherent methods instead
Makes a copy of the value in its ASCII lower case equivalent. Read more
Source§

fn eq_ignore_ascii_case(&self, other: &Self) -> bool

👎Deprecated since 1.26.0: use inherent methods instead
Checks that two values are an ASCII case-insensitive match. Read more
Source§

fn make_ascii_uppercase(&mut self)

👎Deprecated since 1.26.0: use inherent methods instead
Converts this type to its ASCII upper case equivalent in-place. Read more
Source§

fn make_ascii_lowercase(&mut self)

👎Deprecated since 1.26.0: use inherent methods instead
Converts this type to its ASCII lower case equivalent in-place. Read more
Source§

impl Borrow<[AsciiChar]> for PascalString

Source§

fn borrow(&self) -> &[AsciiChar]

Immutably borrows from an owned value. Read more
Source§

impl Borrow<[u8]> for PascalString

Source§

fn borrow(&self) -> &[u8]

Immutably borrows from an owned value. Read more
Source§

impl Borrow<AsciiStr> for PascalString

Source§

fn borrow(&self) -> &AsciiStr

Immutably borrows from an owned value. Read more
Source§

impl Borrow<PascalStr> for PascalString

Source§

fn borrow(&self) -> &PascalStr

Immutably borrows from an owned value. Read more
Source§

impl Borrow<str> for PascalString

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<[AsciiChar]> for PascalString

Source§

fn borrow_mut(&mut self) -> &mut [AsciiChar]

Mutably borrows from an owned value. Read more
Source§

impl BorrowMut<PascalStr> for PascalString

Source§

fn borrow_mut(&mut self) -> &mut PascalStr

Mutably borrows from an owned value. Read more
Source§

impl Clone for PascalString

Source§

fn clone(&self) -> Self

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 Debug for PascalString

Source§

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

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

impl Default for PascalString

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for PascalString

Source§

type Target = PascalStr

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for PascalString

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Display for PascalString

Source§

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

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

impl FromIterator<AsciiChar> for PascalString

Source§

fn from_iter<I: IntoIterator<Item = AsciiChar>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for PascalString

Source§

type Err = PascalStringCreateError

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 Hash for PascalString

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 Into<[u8; 256]> for PascalString

Source§

fn into(self) -> [u8; 256]

Converts this type into the (usually inferred) input type.
Source§

impl Into<AsciiString> for PascalString

Source§

fn into(self) -> AsciiString

Converts this type into the (usually inferred) input type.
Source§

impl Into<String> for PascalString

Source§

fn into(self) -> String

Converts this type into the (usually inferred) input type.
Source§

impl Into<Vec<AsciiChar>> for PascalString

Source§

fn into(self) -> Vec<AsciiChar>

Converts this type into the (usually inferred) input type.
Source§

impl Into<Vec<u8>> for PascalString

Source§

fn into(self) -> Vec<u8>

Converts this type into the (usually inferred) input type.
Source§

impl IntoIterator for PascalString

Source§

type Item = AsciiChar

The type of the elements being iterated over.
Source§

type IntoIter = IntoChars

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for PascalString

Source§

fn cmp(&self, other: &Self) -> 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<S: AsRef<PascalStr> + ?Sized> PartialEq<S> for PascalString

Source§

fn eq(&self, other: &S) -> 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<S: AsRef<PascalStr> + ?Sized> PartialOrd<S> for PascalString

Source§

fn partial_cmp(&self, other: &S) -> 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 Eq for PascalString

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.