/// An [HSTRING] builder that supports preallocating the `HSTRING` to avoid extra allocations and copies. /// /// This is similar to the `WindowsPreallocateStringBuffer` function but implemented directly in Rust for efficiency. /// It is implemented as a separate type since [HSTRING] values are immutable. pubstruct HStringBuilder(*mut HStringHeader);
impl HStringBuilder { /// Creates a preallocated `HSTRING` value. pubfn new(len: usize) -> Result<Self> { let header = HStringHeader::alloc(len.try_into()?)?;
if len > 0 { unsafe { core::ptr::write_bytes((*header).data, 0, len) };
}
Ok(Self(header))
}
/// Shortens the string by removing any trailing 0 characters. pubfn trim_end(&mutself) { iflet Some(header) = self.as_header_mut() { while header.len > 0
&& unsafe { header.data.offset(header.len as isize - 1).read() == 0 }
{
header.len -= 1;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.