Struct tiny_std::UnixStr

source ·
#[repr(transparent)]
pub struct UnixStr(_);

Implementations§

source§

impl UnixStr

source

pub const unsafe fn from_str_unchecked(s: &str) -> &UnixStr

Safety

&str needs to be null terminated or downstream UB may occur

source

pub const fn from_str_checked(s: &str) -> &UnixStr

Const instantiation of a &UnixStr from a &str. Should only be used in a const-context, although rustc does not let me enforce this.

Panics

This method panics since it’s supposed to produce a comptime error, it’s not particularly efficient.

source

pub unsafe fn from_ptr<'a>(s: *const u8) -> &'a UnixStr

Safety

s needs to be null terminated

source

pub fn as_str(&self) -> Result<&str, Utf8Error>

Try to convert this &UnixStr to a utf8 &str

Errors

Not utf8

source

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

Get this &UnixStr as a slice, including the null byte

source

pub fn len(&self) -> usize

Get the length of this &UnixStr, including the null byte

Trait Implementations§

source§

impl AsUnixStr for &UnixStr

source§

fn exec_with_self_as_ptr<F, T>(&self, func: F) -> Result<T, Error>where F: FnOnce(*const u8) -> Result<T, Error>,

Executes a function with this null terminated entity converts it to a string and pushes a null byte if not already null terminated Read more
source§

unsafe fn match_up_to(&self, null_terminated_pointer: *const u8) -> usize

Checks if this AsUnixStr matches a null terminated pointer and returns the non null length Read more
source§

impl AsUnixStr for &mut UnixStr

source§

fn exec_with_self_as_ptr<F, T>(&self, func: F) -> Result<T, Error>where F: FnOnce(*const u8) -> Result<T, Error>,

Executes a function with this null terminated entity converts it to a string and pushes a null byte if not already null terminated Read more
source§

unsafe fn match_up_to(&self, null_terminated_pointer: *const u8) -> usize

Checks if this AsUnixStr matches a null terminated pointer and returns the non null length Read more
source§

impl Debug for UnixStr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl From<&UnixStr> for UnixString

source§

fn from(s: &UnixStr) -> UnixString

Converts to this type from the input type.
source§

impl PartialEq<UnixStr> for UnixStr

source§

fn eq(&self, other: &UnixStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToUnixString for &UnixStr

source§

fn to_unix_string(&self) -> Result<UnixString, Error>

Turn this into a UnixString Read more
source§

impl ToUnixString for &mut UnixStr

source§

fn to_unix_string(&self) -> Result<UnixString, Error>

Turn this into a UnixString Read more
source§

impl Eq for UnixStr

source§

impl StructuralEq for UnixStr

source§

impl StructuralPartialEq for UnixStr

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more