[][src]Trait to_str::ToStr

pub unsafe trait ToStr {
    const TEXT_SIZE: usize;

    fn to_str<'a>(&self, buffer: &'a mut [u8]) -> &'a str;

    fn to_str_if<'a>(&self, buffer: &'a mut [u8]) -> Option<&'a str> { ... }
}

Describes conversion to string

This trait is unsafe due to following requirements:

  • Implementation must never read buffer, unless it was already written by it;
  • It writes from the end of buffer (necessary only when you use Buffer).

Associated Constants

const TEXT_SIZE: usize

Max size in bytes to hold the string

Implementation MUST guarantee that this size of buffer is enough to fit any possible textual representation

Loading content...

Required methods

fn to_str<'a>(&self, buffer: &'a mut [u8]) -> &'a str

Writes textual representation to the buffer

Returns str stored in the provided buffer

Can panic, if buffer is not sufficient. Or write only partially

Implementation is allowed to write any part of the buffer. It is not allowed to read it, unless it was written already.

Safety:

Debug builds must never invoke UB when calling this function.

UB in release mode is fine if one wants to write efficient code.

Loading content...

Provided methods

fn to_str_if<'a>(&self, buffer: &'a mut [u8]) -> Option<&'a str>

Performs textual conversion by writing to the buffer, if possible.

If not possible MUST return None

By default returns None if buffer size is below TEXT_SIZE Otherwise calls to_str() while passing buffer as it is

Loading content...

Implementations on Foreign Types

impl<T> ToStr for AtomicPtr<T>[src]

impl<T> ToStr for NonNull<T>[src]

Loading content...

Implementors

impl ToStr for i8[src]

impl ToStr for i16[src]

impl ToStr for i32[src]

impl ToStr for i64[src]

impl ToStr for i128[src]

impl ToStr for isize[src]

impl ToStr for u8[src]

impl ToStr for u16[src]

impl ToStr for u32[src]

impl ToStr for u64[src]

impl ToStr for u128[src]

impl ToStr for usize[src]

impl<'a, T: ?Sized + ToStr> ToStr for &'a T[src]

impl<'a, T: ?Sized + ToStr> ToStr for &'a mut T[src]

impl<T> ToStr for *const T[src]

impl<T> ToStr for *mut T[src]

Loading content...