[][src]Struct libuv::buf::ReadonlyBuf

pub struct ReadonlyBuf { /* fields omitted */ }

Readonly buffer data type.

Implementations

impl ReadonlyBuf[src]

pub fn is_allocated(&self) -> bool[src]

Returns true if the internal buffer is initialized

pub fn dealloc(&mut self)[src]

Deallocate the internal buffer, but leave the Buf intact. Even though this is a "readonly" Buf, the internal storage can still be deallocated. This oddity is an unfortunate side-effect of the libuv API: for example, StreamHandle::read_start calls the allocate callback to create a Buf, then passes that Buf to the read callback as a ReadonlyBuf. You could run dealloc() in the read callback to deallocate the internal buffer - the allocate callback takes ownership of the actual Buf struct, so you don't need to worry about that.

pub fn as_c_str(&self) -> Result<&CStr, EmptyBufError>[src]

Convert the Buf to a CStr. Returns an error if the Buf is empty. Data contained within the ReadonlyBuf must be null-terminated or this will fail!

pub fn to_string_lossy(&self) -> Result<Cow<'_, str>, EmptyBufError>[src]

Convert the Buf to a string. Returns an error if the Buf is empty. Data contained within the ReadonlyBuf must be null-terminated or this will fail!

pub fn to_str(&self, len: usize) -> Result<&str, Box<dyn Error>>[src]

Convert data in the Buf to a &str. Returns an error if the Buf is empty or the data is not valid utf8. Data does not need to be null-terminated because only the first len bytes will be used to create the string.

Trait Implementations

impl BufTrait for ReadonlyBuf[src]

impl Clone for ReadonlyBuf[src]

impl Copy for ReadonlyBuf[src]

impl From<Buf> for ReadonlyBuf[src]

impl Index<Range<usize>> for ReadonlyBuf[src]

type Output = [u8]

The returned type after indexing.

impl Index<RangeFrom<usize>> for ReadonlyBuf[src]

type Output = [u8]

The returned type after indexing.

impl Index<RangeFull> for ReadonlyBuf[src]

type Output = [u8]

The returned type after indexing.

impl Index<RangeInclusive<usize>> for ReadonlyBuf[src]

type Output = [u8]

The returned type after indexing.

impl Index<RangeTo<usize>> for ReadonlyBuf[src]

type Output = [u8]

The returned type after indexing.

impl Index<RangeToInclusive<usize>> for ReadonlyBuf[src]

type Output = [u8]

The returned type after indexing.

impl Index<usize> for ReadonlyBuf[src]

type Output = u8

The returned type after indexing.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.