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
impl PascalString
Sourcepub fn from_fixed_ascii_array<C>(
string_len: u8,
char_array: [C; 255],
) -> Result<Self, PascalStringCreateError>where
C: ToAsciiChar + Clone,
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.
Sourcepub fn from<B: AsRef<[u8]>>(bytes: B) -> Result<Self, PascalStringCreateError>
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.
Sourcepub fn push<C: ToAsciiChar>(&mut self, character: C)
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.
Sourcepub fn try_push<C: ToAsciiChar>(
&mut self,
character: C,
) -> Result<(), PascalStringAppendError>
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.
Sourcepub fn push_str<S: AsRef<str>>(&mut self, s: S)
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.
Sourcepub fn try_push_str<S: AsRef<str>>(
&mut self,
s: S,
) -> Result<(), PascalStringAppendError>
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.
Sourcepub fn pop(&mut self) -> Option<AsciiChar>
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.
Sourcepub fn remove(&mut self, index: u8) -> AsciiChar
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
.
Sourcepub fn insert<C: ToAsciiChar>(&mut self, ch: C, index: u8)
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.
Methods from Deref<Target = PascalStr>§
Sourcepub fn as_mut_ptr(&mut self) -> *mut AsciiChar
pub fn as_mut_ptr(&mut self) -> *mut AsciiChar
Get a mutable pointer to the first byte of the string buffer.
Sourcepub fn as_cstr(&self) -> Result<Cow<'_, CStr>, InteriorNullError>
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.
Sourcepub fn is_full(&self) -> bool
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.
Sourcepub fn chars<'a>(&'a self) -> Chars<'a> ⓘ
pub fn chars<'a>(&'a self) -> Chars<'a> ⓘ
Get an immutable iterator to the internal character array.
Sourcepub fn chars_mut<'a>(&'a mut self) -> CharsMut<'a> ⓘ
pub fn chars_mut<'a>(&'a mut self) -> CharsMut<'a> ⓘ
Get a mutable iterator to the internal character array.
Sourcepub fn lines(&self) -> Lines<'_> ⓘ
pub fn lines(&self) -> Lines<'_> ⓘ
Get an iterator over the lines of the internal character array.
Sourcepub fn get_unchecked(&self, index: usize) -> AsciiChar
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).