pub struct BSFixedStringInternal<T>where
T: StringFormat,{ /* private fields */ }
Expand description
A fixed-length internal string representation used for interacting with
the BSStringPool
.
This is similar to ::core::ffi::CStr
, but supports both char
and wchar_t
formats
through the StringFormat
trait.
§Type Parameters
T
: The string format (U8
forchar
orU16
forwchar_t
).
§Safety
Since this is an FFI type, the encoding is not guaranteed. It may be UTF-8, ANSI, UTF-16LE, or platform-specific wide encoding.
Implementations§
Source§impl BSFixedStringInternal<U8>
impl BSFixedStringInternal<U8>
Sourcepub fn new(data: &CStr) -> Self
pub fn new(data: &CStr) -> Self
Creates a new BSFixedString
from a &CStr
.
§Memory allocation
- If the same string exists inside the allocator, no new memory allocation occurs.
Sourcepub unsafe fn new_unchecked(data: *const c_char) -> Self
pub unsafe fn new_unchecked(data: *const c_char) -> Self
Source§impl BSFixedStringInternal<U16>
impl BSFixedStringInternal<U16>
Sourcepub const unsafe fn new_unchecked(data: *const u16) -> Self
pub const unsafe fn new_unchecked(data: *const u16) -> Self
§Safety
data
must be a pointer to a null-terminated UTF-16LE string.
Sourcepub fn to_string_lossy(&self) -> String
pub fn to_string_lossy(&self) -> String
Decode a UTF-16–encoded slice v into a String
Source§impl<T> BSFixedStringInternal<T>where
T: StringFormat,
impl<T> BSFixedStringInternal<T>where
T: StringFormat,
Sourcepub fn try_acquire(&self)
pub fn try_acquire(&self)
Tries to acquire a reference to the string in the string pool.
If the string is already in the pool, its reference count is incremented.
Sourcepub fn try_release(&mut self)
pub fn try_release(&mut self)
Tries to release the string from the string pool.
If the string is not null, it decrements its reference count. If the reference count reaches zero, the string is removed from the pool.
Sourcepub const unsafe fn get_proxy(&self) -> Option<&mut Entry<T>>
pub const unsafe fn get_proxy(&self) -> Option<&mut Entry<T>>
Gets a mutable reference to the BSStringPool::Entry
.
Returns None
if the string data is null.
§Safety
This dereferences a pointer that may point to invalid memory.
Sourcepub fn count_bytes_with_null(&self) -> u32
pub fn count_bytes_with_null(&self) -> u32
Returns the length of the string.
Returns 0
if the string data is null or the proxy is invalid.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks whether the string is empty.
Returns true
if the string length is zero.
Sourcepub fn as_bytes_with_null(&self) -> &[u8] ⓘ
pub fn as_bytes_with_null(&self) -> &[u8] ⓘ
Converts this C string as a byte slice with null.