embedded_nal

Struct SharableStack

Source
pub struct SharableStack<T> { /* private fields */ }
Expand description

Sharable wrapper for a network stack implementation.

An implementation of the stack traits that can contain (and provide provide single-threaded shared access to) another stack implementation. A direct implementation can only be used when owned or with a mutable reference. This implementation will store another implementation internally, and yield an arbitrary number of shared references to it, which themselves implement the stack traits.

use embedded_nal::SharableStack;
let mut driver = SomeNalDriver::new();
// Driver can only be used in one place at a time.
let mut sharable_driver = SharableStack::new(driver);
// Sharable driver can't do anything on its own, but it can create many usable copies.
let mut shared_driver0 = sharable_driver.acquire();
let mut shared_driver1 = sharable_driver.acquire();
// These shared copies can be passed around to other parts of an application's code, and used
// independently.
let mut socket0 = shared_driver0.socket()?;
shared_driver0.connect(&mut socket0, SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080)));
// ...

// ... and somewhere else
let mut socket1 = shared_driver1.socket()?;
shared_driver1.connect(&mut socket1, SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8443)));
// ...

Implementations§

Source§

impl<T> SharableStack<T>

Source

pub fn new(stack: T) -> Self

Create a new SharedStack that contains and uses some other stack implementation.

Source

pub fn acquire(&self) -> SharedStack<'_, T>

Returns a shared reference to the driver that can be used as a first-class implementation.

Auto Trait Implementations§

§

impl<T> !Freeze for SharableStack<T>

§

impl<T> !RefUnwindSafe for SharableStack<T>

§

impl<T> Send for SharableStack<T>
where T: Send,

§

impl<T> !Sync for SharableStack<T>

§

impl<T> Unpin for SharableStack<T>
where T: Unpin,

§

impl<T> UnwindSafe for SharableStack<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.