pub struct MysteryString(/* private fields */);Expand description
A string whose encoding is defined by the IO system, but probably treated as Latin-1.
Strings of this type can be serialized into a story file (via the
Item::MysteryString) constructor formatted
compatibly with the streamstr instruction. Constructors ensure that it
will not contain any embedded nulls. Internally it’s a Bytes, so cloning
it is cheap.
This corresponds to a Glulx E0 string, of which the spec says “the
encoding scheme is the business of the I/O system; in Glk, it will be the
Latin-1 character set”. It is in any case required to be a single-byte
encoding which uses a zero byte as a terminator.
When building a MysteryString from a char iterator or using its
Display impl, Latin1 is assumed. However, you can also build it from a
u8 iterator in which case no assumption is made about the encoding.
Implementations§
Source§impl MysteryString
impl MysteryString
Sourcepub fn from_chars<I, C>(chars: I) -> Result<Self, StringConversionError<Self>>
pub fn from_chars<I, C>(chars: I) -> Result<Self, StringConversionError<Self>>
Constructs a MysteryString from an iterator over chars (or over any
type that lets you borrow a char).
If the string contains embedded nulls or any character which cannot be
represented in Latin-1, an error is returned, but a lossy version can be
extracted from the error struct. The lossy string replaces nulls and
unrepresentable characters with b'?'.
Sourcepub fn from_bytes<I, C>(chars: I) -> Result<Self, StringConversionError<Self>>
pub fn from_bytes<I, C>(chars: I) -> Result<Self, StringConversionError<Self>>
Constructs a MysteryString from an iterator over u8s (or over any
type that lets you borrow a u8).
If the string contains embedded nulls, an error is returned, but a lossy
version can be extracted from the error struct. The lossy string is
truncated at the first occurence of a null. (Unlike from_chars, this
constructor doesn’t that the string is Latin-1 or even any ASCII
superset, so therefore it can’t know what would be a reasonable
replacement character to substitute.)
Sourcepub fn from_chars_lossy<I, C>(chars: I) -> Self
pub fn from_chars_lossy<I, C>(chars: I) -> Self
Like from_chars, but in case of error will
silently unwrap the error and return the lossy version.
Sourcepub fn from_bytes_lossy<I, C>(chars: I) -> Self
pub fn from_bytes_lossy<I, C>(chars: I) -> Self
Like from_bytes, but in case of error will
silently unwrap the error and return the lossy version.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the string, excluding prefix and null terminator.
Sourcepub fn len_with_prefix_and_nul(&self) -> usize
pub fn len_with_prefix_and_nul(&self) -> usize
Returns the length of the string, including prefix and null terminator.
Sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Unwraps the string into its underlying Bytes.
Trait Implementations§
Source§impl Clone for MysteryString
impl Clone for MysteryString
Source§fn clone(&self) -> MysteryString
fn clone(&self) -> MysteryString
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MysteryString
impl Debug for MysteryString
Source§impl Default for MysteryString
impl Default for MysteryString
Source§fn default() -> MysteryString
fn default() -> MysteryString
Source§impl Display for MysteryString
impl Display for MysteryString
Source§impl Hash for MysteryString
impl Hash for MysteryString
Source§impl PartialEq for MysteryString
impl PartialEq for MysteryString
Source§impl TryFrom<&[u8]> for MysteryString
impl TryFrom<&[u8]> for MysteryString
Source§impl TryFrom<&String> for MysteryString
impl TryFrom<&String> for MysteryString
Source§impl TryFrom<&str> for MysteryString
impl TryFrom<&str> for MysteryString
Source§impl TryFrom<String> for MysteryString
impl TryFrom<String> for MysteryString
impl Eq for MysteryString
impl StructuralPartialEq for MysteryString
Auto Trait Implementations§
impl !Freeze for MysteryString
impl RefUnwindSafe for MysteryString
impl Send for MysteryString
impl Sync for MysteryString
impl Unpin for MysteryString
impl UnwindSafe for MysteryString
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)