Struct Window
pub struct Window<T> { /* private fields */ }
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) -> &TGets a shared reference to the underlying buffer inside of this
Window.fn get_mut(&mut self) -> &mut TGets a mutable reference to the underlying buffer inside of this
Window.fn into_inner(self) -> TConsumes this
Window, returning the underlying buffer.fn start(&self) -> usizeReturns the starting index of this window into the underlying buffer
T.fn end(&self) -> usizeReturns the end index of this window into the underlying buffer
T.fn set<R: RangeBounds<usize>>(&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().
Trait Implementations
impl<T: AsMut<[u8]>> AsMut<[u8]> for Window<T>
fn as_mut(&mut self) -> &mut [u8]
impl<T: AsRef<[u8]>> AsRef<[u8]> for Window<T>
fn as_ref(&self) -> &[u8]
impl<T: Debug> Debug for Window<T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<T> Freeze for Window<T>
where
T: Freeze,
impl<T> RefUnwindSafe for Window<T>
where
T: RefUnwindSafe,
impl<T> Send for Window<T>
where
T: Send,
impl<T> Sync for Window<T>
where
T: Sync,
impl<T> Unpin for Window<T>
where
T: Unpin,
impl<T> UnsafeUnpin for Window<T>
where
T: UnsafeUnpin,
impl<T> UnwindSafe for Window<T>
where
T: UnwindSafe,
Blanket Implementations
impl<T> Any for Window<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Window<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Window<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for Window<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for Window<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Window<T>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Window<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>