pub struct AString<const CP: u32> { /* private fields */ }Expand description
An owned NUL-terminated ANSI string for code page CP.
A valid AString<CP> contains bytes accepted by Windows for code page CP,
followed by exactly one terminating NUL in the retained string.
Safe constructors reject interior NULs and invalid byte sequences.
Unsafe constructors rely on the caller to preserve those invariants.
Implementations§
Source§impl<const CP: u32> AString<CP>
impl<const CP: u32> AString<CP>
Sourcepub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Returns the mutable bytes excluding the terminating NUL.
§Safety
The caller must preserve a string valid for code page CP without
interior NULs.
Sourcepub fn as_bytes_with_nul(&self) -> &[u8] ⓘ
pub fn as_bytes_with_nul(&self) -> &[u8] ⓘ
Returns the bytes including the terminating NUL.
Sourcepub unsafe fn as_bytes_with_nul_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn as_bytes_with_nul_mut(&mut self) -> &mut [u8] ⓘ
Returns the mutable bytes including the terminating NUL.
§Safety
The caller must preserve a valid, NUL-terminated string for code page
CP without interior NULs.
Sourcepub fn len_with_nul(&self) -> usize
pub fn len_with_nul(&self) -> usize
Returns the length of bytes including the terminating NUL.
Sourcepub fn as_mut_astr(&mut self) -> &mut AStr<CP>
pub fn as_mut_astr(&mut self) -> &mut AStr<CP>
Returns the string as a mutable borrowed AStr.
Sourcepub fn new<T: Into<Vec<u8>>>(v: T) -> ConvertResult<Self>
pub fn new<T: Into<Vec<u8>>>(v: T) -> ConvertResult<Self>
Constructs an AString from bytes in code page CP.
The input must be valid for code page CP and must not contain
interior NULs. If it is not NUL-terminated, a terminating NUL is appended.
Sourcepub fn from_vec_with_nul<T: Into<Vec<u8>>>(v: T) -> ConvertResult<Self>
pub fn from_vec_with_nul<T: Into<Vec<u8>>>(v: T) -> ConvertResult<Self>
Constructs an AString from NUL-terminated bytes in code page CP.
The input must be valid for code page CP, must end with a NUL byte,
and must not contain interior NULs.
Sourcepub fn from_vec_until_nul<T: Into<Vec<u8>>>(v: T) -> ConvertResult<Self>
pub fn from_vec_until_nul<T: Into<Vec<u8>>>(v: T) -> ConvertResult<Self>
Constructs an AString from bytes in code page CP.
If the input contains a NUL, the string is truncated at the first NUL. If the input contains no NUL, a terminating NUL is appended.
Sourcepub unsafe fn from_vec_unchecked<T: Into<Vec<u8>>>(v: T) -> Self
pub unsafe fn from_vec_unchecked<T: Into<Vec<u8>>>(v: T) -> Self
Sourcepub unsafe fn from_vec_with_nul_unchecked<T: Into<Vec<u8>>>(v: T) -> Self
pub unsafe fn from_vec_with_nul_unchecked<T: Into<Vec<u8>>>(v: T) -> Self
Sourcepub fn from_utf8(s: impl AsRef<str>) -> ConvertResult<Self>
pub fn from_utf8(s: impl AsRef<str>) -> ConvertResult<Self>
Converts UTF-8 text to an AString using code page CP.
Sourcepub fn try_from_utf8_lossy(s: impl AsRef<str>) -> ConvertResult<Self>
pub fn try_from_utf8_lossy(s: impl AsRef<str>) -> ConvertResult<Self>
Attempts to convert UTF-8 text to an AString using replacement when required by code page CP.
Embedded NUL characters are replaced before conversion. This can still
fail if Windows rejects CP or the conversion parameters.
Sourcepub fn from_utf8_lossy(s: impl AsRef<str>) -> Self
pub fn from_utf8_lossy(s: impl AsRef<str>) -> Self
Converts UTF-8 text to an AString using replacement when required by code page CP.
§Panics
Panics if Windows rejects CP or if the underlying lossy conversion fails.
Use try_from_utf8_lossy to handle that error explicitly.
Sourcepub unsafe fn clone_from_raw(ptr: *const u8) -> Self
pub unsafe fn clone_from_raw(ptr: *const u8) -> Self
Copies an AString from a raw NUL-terminated pointer.
This function scans for the first NUL with strlen,
then delegates to clone_from_raw_s.
§Safety
ptr must be non-null and readable through the first NUL.
The scanned range must be contained in a single allocated object and must not exceed
isize::MAX bytes. The pointed-to data before the first NUL must be
valid for code page CP and must not contain interior NULs.
Sourcepub unsafe fn clone_from_raw_s(ptr: *const u8, len: usize) -> Self
pub unsafe fn clone_from_raw_s(ptr: *const u8, len: usize) -> Self
Copies an AString from a raw pointer and explicit copied byte length without scanning for a terminator.
len is the number of bytes copied from ptr.
This function does not read ptr.add(len).
If the copied range does not already end in NUL, a terminating NUL is appended to the new AString.
§Safety
ptr must be non-null and readable for len bytes.
The copied range must be contained in a single allocated object and must not exceed isize::MAX bytes.
The copied data must be valid for code page CP and must not contain NULs except possibly as the final copied byte.
Sourcepub fn into_bytes_with_nul(self) -> Vec<u8> ⓘ
pub fn into_bytes_with_nul(self) -> Vec<u8> ⓘ
Consumes the string and returns the internal NUL-terminated buffer.
Methods from Deref<Target = AStr<CP>>§
Sourcepub fn len_with_nul(&self) -> usize
pub fn len_with_nul(&self) -> usize
Returns the length of bytes including the terminating NUL.
Sourcepub fn as_bytes_with_nul(&self) -> &[u8] ⓘ
pub fn as_bytes_with_nul(&self) -> &[u8] ⓘ
Returns the bytes including the terminating NUL.
Sourcepub fn try_to_string(&self) -> ConvertResult<String>
pub fn try_to_string(&self) -> ConvertResult<String>
Converts this borrowed ANSI string to a UTF-8 String.
This method returns a ConvertError if Windows rejects the code page or byte sequence.
Values produced by unsafe constructors are not revalidated before conversion.
Trait Implementations§
impl<const CP: u32> Eq for AString<CP>
Source§impl<const CP: u32> Ord for AString<CP>
impl<const CP: u32> Ord for AString<CP>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a, const CP: u32> PartialEq<AString<CP>> for DAStr<'a>
Available on crate feature std only.
impl<'a, const CP: u32> PartialEq<AString<CP>> for DAStr<'a>
std only.Source§impl<const CP: u32> PartialOrd for AString<CP>
impl<const CP: u32> PartialOrd for AString<CP>
Source§impl<const CP: u32> PartialOrd<&AStr<CP>> for AString<CP>
impl<const CP: u32> PartialOrd<&AStr<CP>> for AString<CP>
Source§impl<const CP: u32> PartialOrd<&AString<CP>> for AStr<CP>
Available on crate feature std only.
impl<const CP: u32> PartialOrd<&AString<CP>> for AStr<CP>
std only.Source§impl<const CP: u32> PartialOrd<AStr<CP>> for AString<CP>
impl<const CP: u32> PartialOrd<AStr<CP>> for AString<CP>
Source§impl<const CP: u32> PartialOrd<AString<CP>> for AStr<CP>
Available on crate feature std only.
impl<const CP: u32> PartialOrd<AString<CP>> for AStr<CP>
std only.