Struct smoldot_light::platform::with_buffers::ReadWriteAccess
source · pub struct ReadWriteAccess<'a, TNow>where
TNow: Clone,{ /* private fields */ }
Expand description
Methods from Deref<Target = ReadWrite<TNow>>§
sourcepub fn is_dead(&self) -> bool
pub fn is_dead(&self) -> bool
Returns true if the connection should be considered dead. That is, both
ReadWrite::expected_incoming_bytes
is None
and ReadWrite::write_bytes_queueable
is None
.
sourcepub fn close_write(&mut self)
pub fn close_write(&mut self)
Sets the writing side of the connection to closed.
This is simply a shortcut for setting ReadWrite::write_bytes_queueable
to None
.
sourcepub fn incoming_buffer_available(&self) -> usize
pub fn incoming_buffer_available(&self) -> usize
Returns the size of the data available in the incoming buffer.
sourcepub fn discard_all_incoming(&mut self)
pub fn discard_all_incoming(&mut self)
Discards all the incoming data. Updates ReadWrite::read_bytes
and decreases
ReadWrite::expected_incoming_bytes
by the number of consumed bytes.
sourcepub fn incoming_bytes_take(
&mut self,
num: usize,
) -> Result<Option<Vec<u8>>, IncomingBytesTakeError>
pub fn incoming_bytes_take( &mut self, num: usize, ) -> Result<Option<Vec<u8>>, IncomingBytesTakeError>
Extract a certain number of bytes from the read buffer.
On success, updates ReadWrite::read_bytes
and decreases
ReadWrite::expected_incoming_bytes
by the number of consumed bytes.
If not enough bytes are available, returns None
and sets
ReadWrite::expected_incoming_bytes
to the requested number of bytes.
sourcepub fn incoming_bytes_take_array<const N: usize>(
&mut self,
) -> Result<Option<[u8; N]>, IncomingBytesTakeError>
pub fn incoming_bytes_take_array<const N: usize>( &mut self, ) -> Result<Option<[u8; N]>, IncomingBytesTakeError>
Same as ReadWrite::incoming_bytes_take_array
, but reads a number of bytes as a
compile-time constant.
sourcepub fn incoming_bytes_take_leb128(
&mut self,
max_decoded_number: usize,
) -> Result<Option<usize>, IncomingBytesTakeLeb128Error>
pub fn incoming_bytes_take_leb128( &mut self, max_decoded_number: usize, ) -> Result<Option<usize>, IncomingBytesTakeLeb128Error>
Extract an LEB128-encoded number from the start of the read buffer.
On success, updates ReadWrite::read_bytes
and decreases
ReadWrite::expected_incoming_bytes
by the number of consumed bytes.
If not enough bytes are available, returns None
and sets
ReadWrite::expected_incoming_bytes
to the required number of bytes.
Must be passed the maximum value that this function can return on success. An error is returned if the value sent by the remote is higher than this maximum. This parameter, while not strictly necessary, is here for safety, as it is easy to forget to check the value against a maximum.
sourcepub fn write_from_vec(&mut self, data: &mut Vec<u8>)
pub fn write_from_vec(&mut self, data: &mut Vec<u8>)
Copies as much as possible from the content of data
to ReadWrite::write_buffers
and updates ReadWrite::write_bytes_queued
and ReadWrite::write_bytes_queueable
.
The bytes that have been written are removed from data
.
This function is recommended only if the Vec
is small.
sourcepub fn write_from_vec_deque(&mut self, data: &mut VecDeque<u8>)
pub fn write_from_vec_deque(&mut self, data: &mut VecDeque<u8>)
Copies as much as possible from the content of data
to ReadWrite::write_buffers
and updates ReadWrite::write_bytes_queued
and ReadWrite::write_bytes_queueable
.
The bytes that have been written are removed from data
.
sourcepub fn write_out(&mut self, data: Vec<u8>)
pub fn write_out(&mut self, data: Vec<u8>)
Adds the data
to ReadWrite::write_buffers
, increases
ReadWrite::write_bytes_queued
, and decreases ReadWrite::write_bytes_queueable
.
§Panic
Panics if data.len() > write_bytes_queueable
.
Panics if the writing side is closed and data
isn’t empty.
sourcepub fn wake_up_after(&mut self, after: &TNow)
pub fn wake_up_after(&mut self, after: &TNow)
Sets ReadWrite::wake_up_after
to min(wake_up_after, after)
.
sourcepub fn wake_up_asap(&mut self)where
TNow: Clone,
pub fn wake_up_asap(&mut self)where
TNow: Clone,
Sets ReadWrite::wake_up_after
to the value in ReadWrite::now
.
Trait Implementations§
source§impl<'a, TNow> Deref for ReadWriteAccess<'a, TNow>where
TNow: Clone,
impl<'a, TNow> Deref for ReadWriteAccess<'a, TNow>where
TNow: Clone,
source§impl<'a, TNow> DerefMut for ReadWriteAccess<'a, TNow>where
TNow: Clone,
impl<'a, TNow> DerefMut for ReadWriteAccess<'a, TNow>where
TNow: Clone,
Auto Trait Implementations§
impl<'a, TNow> Freeze for ReadWriteAccess<'a, TNow>where
TNow: Freeze,
impl<'a, TNow> RefUnwindSafe for ReadWriteAccess<'a, TNow>where
TNow: RefUnwindSafe,
impl<'a, TNow> Send for ReadWriteAccess<'a, TNow>where
TNow: Send,
impl<'a, TNow> Sync for ReadWriteAccess<'a, TNow>where
TNow: Sync,
impl<'a, TNow> Unpin for ReadWriteAccess<'a, TNow>where
TNow: Unpin,
impl<'a, TNow> !UnwindSafe for ReadWriteAccess<'a, TNow>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more