Struct Window
struct Window<T> { ... }
An owned window around an underlying buffer.
Normally slices work great for considering sub-portions of a buffer, but unfortunately a slice is a borrowed type in Rust which has an associated lifetime. When working with future and async I/O these lifetimes are not always appropriate, and are sometimes difficult to store in tasks. This type strives to fill this gap by providing an "owned slice" around an underlying buffer of bytes.
A Window<T> wraps an underlying buffer, T, and has configurable
start/end indexes to alter the behavior of the AsRef<[u8]> implementation
that this type carries.
This type can be particularly useful when working with the write_all
combinator in this crate. Data can be sliced via Window, consumed by
write_all, and then earned back once the write operation finishes through
the into_inner method on this type.
Implementations
impl<T: AsRef<[u8]>> Window<T>
fn new(t: T) -> SelfCreates a new window around the buffer
tdefaulting to the entire slice.Further methods can be called on the returned
Window<T>to alter the window into the data provided.fn get_ref(self: &Self) -> &TGets a shared reference to the underlying buffer inside of this
Window.fn get_mut(self: &mut Self) -> &mut TGets a mutable reference to the underlying buffer inside of this
Window.fn into_inner(self: Self) -> TConsumes this
Window, returning the underlying buffer.fn start(self: &Self) -> usizeReturns the starting index of this window into the underlying buffer
T.fn end(self: &Self) -> usizeReturns the end index of this window into the underlying buffer
T.fn set<R: RangeBounds<usize>>(self: &mut Self, range: R)Changes the range of this window to the range specified.
Panics
This method will panic if
rangeis out of bounds for the underlying slice or ifstart_bound()ofrangecomes after theend_bound().
impl<T> Any for Window<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Window<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Window<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Freeze for Window<T>
impl<T> From for Window<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for Window<T>
impl<T> Send for Window<T>
impl<T> Sync for Window<T>
impl<T> Unpin for Window<T>
impl<T> UnsafeUnpin for Window<T>
impl<T> UnwindSafe for Window<T>
impl<T, U> Into for Window<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Window<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Window<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: $crate::fmt::Debug> Debug for Window<T>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<T: AsMut<[u8]>> AsMut for Window<T>
fn as_mut(self: &mut Self) -> &mut [u8]
impl<T: AsRef<[u8]>> AsRef for Window<T>
fn as_ref(self: &Self) -> &[u8]