pub struct UdpFramed<C> { /* private fields */ }
Expand description
A unified Stream
and Sink
interface to an underlying UdpSocket
, using
the Encoder
and Decoder
traits to encode and decode frames.
Raw UDP sockets work with datagrams, but higher-level code usually wants to
batch these into meaningful chunks, called “frames”. This method layers
framing on top of this socket by using the Encoder
and Decoder
traits to
handle encoding and decoding of messages frames. Note that the incoming and
outgoing frame types may be distinct.
This function returns a single object that is both Stream
and Sink
;
grouping this into a single object is often useful for layering things which
require both read and write access to the underlying object.
If you want to work more directly with the streams and sink, consider
calling split
on the UdpFramed
returned by this method, which will break
them into separate objects, allowing them to interact more easily.
Implementations§
Source§impl<C> UdpFramed<C>
impl<C> UdpFramed<C>
Sourcepub fn new(socket: UdpSocket, codec: C) -> UdpFramed<C>
pub fn new(socket: UdpSocket, codec: C) -> UdpFramed<C>
Create a new UdpFramed
backed by the given socket and codec.
See struct level documentation for more details.
Sourcepub fn with_decode(
socket: UdpSocket,
codec: C,
repeat_decode: bool,
) -> UdpFramed<C>
pub fn with_decode( socket: UdpSocket, codec: C, repeat_decode: bool, ) -> UdpFramed<C>
Create a new UdpFramed
backed by the given socket and codec. That will
continue to call decode_eof
until the decoder has cleared the entire buffer.
See struct level documentation for more details.
Sourcepub fn get_ref(&self) -> &UdpSocket
pub fn get_ref(&self) -> &UdpSocket
Returns a reference to the underlying I/O stream wrapped by Framed
.
§Note
Care should be taken to not tamper with the underlying stream of data coming in as it may corrupt the stream of frames otherwise being worked with.
Sourcepub fn get_mut(&mut self) -> &mut UdpSocket
pub fn get_mut(&mut self) -> &mut UdpSocket
Returns a mutable reference to the underlying I/O stream wrapped by
Framed
.
§Note
Care should be taken to not tamper with the underlying stream of data coming in as it may corrupt the stream of frames otherwise being worked with.
Sourcepub fn into_inner(self) -> UdpSocket
pub fn into_inner(self) -> UdpSocket
Consumes the Framed
, returning its underlying I/O stream.
Trait Implementations§
Source§impl<C: Encoder> Sink for UdpFramed<C>
impl<C: Encoder> Sink for UdpFramed<C>
Source§type SinkError = <C as Encoder>::Error
type SinkError = <C as Encoder>::Error
Source§fn start_send(
&mut self,
item: Self::SinkItem,
) -> StartSend<Self::SinkItem, Self::SinkError>
fn start_send( &mut self, item: Self::SinkItem, ) -> StartSend<Self::SinkItem, Self::SinkError>
Source§fn poll_complete(&mut self) -> Poll<(), C::Error>
fn poll_complete(&mut self) -> Poll<(), C::Error>
Source§fn close(&mut self) -> Poll<(), C::Error>
fn close(&mut self) -> Poll<(), C::Error>
Source§fn wait(self) -> Wait<Self>where
Self: Sized,
fn wait(self) -> Wait<Self>where
Self: Sized,
Source§fn with<U, F, Fut>(self, f: F) -> With<Self, U, F, Fut>where
F: FnMut(U) -> Fut,
Fut: IntoFuture<Item = Self::SinkItem>,
<Fut as IntoFuture>::Error: From<Self::SinkError>,
Self: Sized,
fn with<U, F, Fut>(self, f: F) -> With<Self, U, F, Fut>where
F: FnMut(U) -> Fut,
Fut: IntoFuture<Item = Self::SinkItem>,
<Fut as IntoFuture>::Error: From<Self::SinkError>,
Self: Sized,
Source§fn with_flat_map<U, F, St>(self, f: F) -> WithFlatMap<Self, U, F, St>
fn with_flat_map<U, F, St>(self, f: F) -> WithFlatMap<Self, U, F, St>
Source§fn sink_map_err<F, E>(self, f: F) -> SinkMapErr<Self, F>
fn sink_map_err<F, E>(self, f: F) -> SinkMapErr<Self, F>
Source§fn sink_from_err<E>(self) -> SinkFromErr<Self, E>
fn sink_from_err<E>(self) -> SinkFromErr<Self, E>
From
for this sink’s
Error
, returning a new sink. Read moreSource§fn buffer(self, amt: usize) -> Buffer<Self>where
Self: Sized,
fn buffer(self, amt: usize) -> Buffer<Self>where
Self: Sized,
Source§fn flush(self) -> Flush<Self>where
Self: Sized,
fn flush(self) -> Flush<Self>where
Self: Sized,
Source§impl<C: Decoder> Stream for UdpFramed<C>
impl<C: Decoder> Stream for UdpFramed<C>
Source§type Item = (<C as Decoder>::Item, SocketAddr)
type Item = (<C as Decoder>::Item, SocketAddr)
Source§fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
None
if
the stream is finished. Read moreSource§fn wait(self) -> Wait<Self>where
Self: Sized,
fn wait(self) -> Wait<Self>where
Self: Sized,
Source§fn into_future(self) -> StreamFuture<Self>where
Self: Sized,
fn into_future(self) -> StreamFuture<Self>where
Self: Sized,
Future
. Read moreSource§fn filter<F>(self, f: F) -> Filter<Self, F>
fn filter<F>(self, f: F) -> Filter<Self, F>
Source§fn filter_map<F, B>(self, f: F) -> FilterMap<Self, F>
fn filter_map<F, B>(self, f: F) -> FilterMap<Self, F>
Source§fn then<F, U>(self, f: F) -> Then<Self, F, U>
fn then<F, U>(self, f: F) -> Then<Self, F, U>
f
. Read moreSource§fn and_then<F, U>(self, f: F) -> AndThen<Self, F, U>
fn and_then<F, U>(self, f: F) -> AndThen<Self, F, U>
f
. Read moreSource§fn or_else<F, U>(self, f: F) -> OrElse<Self, F, U>
fn or_else<F, U>(self, f: F) -> OrElse<Self, F, U>
f
. Read moreSource§fn collect(self) -> Collect<Self>where
Self: Sized,
fn collect(self) -> Collect<Self>where
Self: Sized,
Source§fn concat2(self) -> Concat2<Self>
fn concat2(self) -> Concat2<Self>
Source§fn concat(self) -> Concat<Self>
fn concat(self) -> Concat<Self>
Stream::concat2
insteadSource§fn fold<F, T, Fut>(self, init: T, f: F) -> Fold<Self, F, Fut, T>where
F: FnMut(T, Self::Item) -> Fut,
Fut: IntoFuture<Item = T>,
Self::Error: From<<Fut as IntoFuture>::Error>,
Self: Sized,
fn fold<F, T, Fut>(self, init: T, f: F) -> Fold<Self, F, Fut, T>where
F: FnMut(T, Self::Item) -> Fut,
Fut: IntoFuture<Item = T>,
Self::Error: From<<Fut as IntoFuture>::Error>,
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn skip_while<P, R>(self, pred: P) -> SkipWhile<Self, P, R>
fn skip_while<P, R>(self, pred: P) -> SkipWhile<Self, P, R>
true
. Read moreSource§fn take_while<P, R>(self, pred: P) -> TakeWhile<Self, P, R>
fn take_while<P, R>(self, pred: P) -> TakeWhile<Self, P, R>
true
. Read moreSource§fn for_each<F, U>(self, f: F) -> ForEach<Self, F, U>
fn for_each<F, U>(self, f: F) -> ForEach<Self, F, U>
Source§fn from_err<E>(self) -> FromErr<Self, E>
fn from_err<E>(self) -> FromErr<Self, E>
From
for
this stream’s Error
, returning a new stream. Read moreSource§fn take(self, amt: u64) -> Take<Self>where
Self: Sized,
fn take(self, amt: u64) -> Take<Self>where
Self: Sized,
amt
items of the underlying stream. Read moreSource§fn skip(self, amt: u64) -> Skip<Self>where
Self: Sized,
fn skip(self, amt: u64) -> Skip<Self>where
Self: Sized,
amt
items of the underlying stream. Read moreSource§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll
will never again be called once it has
finished. Read moreSource§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn buffered(self, amt: usize) -> Buffered<Self>
fn buffered(self, amt: usize) -> Buffered<Self>
Source§fn buffer_unordered(self, amt: usize) -> BufferUnordered<Self>
fn buffer_unordered(self, amt: usize) -> BufferUnordered<Self>
Source§fn merge<S>(self, other: S) -> Merge<Self, S>
fn merge<S>(self, other: S) -> Merge<Self, S>
select
nowSource§fn zip<S>(self, other: S) -> Zip<Self, S>
fn zip<S>(self, other: S) -> Zip<Self, S>
Source§fn peekable(self) -> Peekable<Self>where
Self: Sized,
fn peekable(self) -> Peekable<Self>where
Self: Sized,
peek
method. Read more