Struct BSFixedStringInternal

Source
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 for char or U16 for wchar_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>

Source

pub const DEFAULT: Self

const default

Source

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.
Source

pub unsafe fn new_unchecked(data: *const c_char) -> Self

Creates a new BSFixedString from a raw pointer.

§Safety
  • data must be a valid null-terminated char string.
§Memory allocation
  • If the same string exists inside the allocator, no new memory allocation occurs.
Source

pub fn as_c_str(&self) -> &CStr

Gets the string as a CStr.

§Encoding

The returned string may not be UTF-8 due to its FFI nature. It is safe to use this as a raw CStr, but converting to str should be done carefully.

Source

pub fn to_str(&self) -> Option<&str>

Converts the string to &str if it is valid UTF-8.

Source

pub fn contains(&self, rhs: &CStr) -> bool

Returns true if CStr passed as argument is contained in this string or not.

Source§

impl BSFixedStringInternal<U16>

Source

pub const EMPTY: &'static [u16]

A constant pointer to an empty string.

Source

pub const unsafe fn new_unchecked(data: *const u16) -> Self

§Safety

data must be a pointer to a null-terminated UTF-16LE string.

Source

pub fn as_wide(&self) -> &[u16]

Convert as [u16]

Source

pub fn to_string_lossy(&self) -> String

Decode a UTF-16–encoded slice v into a String

Source

pub fn to_string(&self) -> Result<String, FromUtf16Error>

Decode a UTF-16–encoded vector v into a String.

§Errors

Invalid UTF-16 encoding

Source§

impl<T> BSFixedStringInternal<T>
where T: StringFormat,

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Checks whether the string is empty.

Returns true if the string length is zero.

Source

pub fn as_bytes_with_null(&self) -> &[u8]

Converts this C string as a byte slice with null.

Trait Implementations§

Source§

impl<T: StringFormat> Clone for BSFixedStringInternal<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: StringFormat> Drop for BSFixedStringInternal<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more