pub unsafe trait ToStr {
const TEXT_SIZE: usize;
// Required method
fn to_str<'a>(&self, buffer: &'a mut [u8]) -> &'a str;
// Provided method
fn to_str_if<'a>(&self, buffer: &'a mut [u8]) -> Option<&'a str> { ... }
}
Expand description
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
).
Required Associated Constants§
Required Methods§
Sourcefn to_str<'a>(&self, buffer: &'a mut [u8]) -> &'a str
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.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.