Skip to main content

AtomicChannelId

Struct AtomicChannelId 

Source
pub struct AtomicChannelId { /* private fields */ }
Available on crate feature api only.
Expand description

A ChannelId which can be shared and updated atomically.

This behaves like an atomic variable holding a ChannelId, where the value can be read, set, replaced, or taken. Each operation takes an Ordering which is passed through to the underlying atomic.

§Examples

use core::sync::atomic::Ordering;

use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::NONE;
assert_eq!(channel.load(Ordering::Acquire), ChannelId::NONE);

channel.store(ChannelId::from_u16(42), Ordering::Release);
assert_eq!(channel.load(Ordering::Acquire), ChannelId::from_u16(42));

assert_eq!(channel.take(Ordering::AcqRel), ChannelId::from_u16(42));
assert_eq!(channel.load(Ordering::Acquire), ChannelId::NONE);

Implementations§

Source§

impl AtomicChannelId

Source

pub const NONE: Self

An atomic channel id which contains ChannelId::NONE.

Since this is a constant every use of it constructs a new value, to share one it has to be bound to a static or a variable.

§Examples
use core::sync::atomic::Ordering;

use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::NONE;
assert_eq!(channel.load(Ordering::Acquire), ChannelId::NONE);
Source

pub const fn new(id: ChannelId) -> Self

Construct a new atomic channel id containing id.

§Examples
use core::sync::atomic::Ordering;

use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::new(ChannelId::from_u16(1));
assert_eq!(channel.load(Ordering::Acquire), ChannelId::from_u16(1));
Source

pub fn load(&self, ordering: Ordering) -> ChannelId

Read the current channel id.

ordering describes the memory ordering of this operation. Possible values are SeqCst, Acquire and Relaxed.

§Panics

Panics if ordering is Release or AcqRel.

§Examples
use core::sync::atomic::Ordering;

use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::new(ChannelId::from_u16(1));
assert_eq!(channel.load(Ordering::Acquire), ChannelId::from_u16(1));
Source

pub fn store(&self, id: ChannelId, ordering: Ordering)

Set the current channel id to id, discarding the old value.

ordering describes the memory ordering of this operation. Possible values are SeqCst, Release and Relaxed.

§Panics

Panics if ordering is Acquire or AcqRel.

§Examples
use core::sync::atomic::Ordering;

use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::NONE;
channel.store(ChannelId::from_u16(1), Ordering::Release);
assert_eq!(channel.load(Ordering::Acquire), ChannelId::from_u16(1));
Source

pub fn replace(&self, id: ChannelId, ordering: Ordering) -> ChannelId

Replace the current channel id with id, returning the old value.

ordering describes the memory ordering of this operation. All orderings are possible. Note that using Acquire makes the store part of this operation Relaxed, and using Release makes the load part Relaxed.

§Examples
use core::sync::atomic::Ordering;

use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::new(ChannelId::from_u16(1));

let old = channel.replace(ChannelId::from_u16(2), Ordering::AcqRel);
assert_eq!(old, ChannelId::from_u16(1));
assert_eq!(channel.load(Ordering::Acquire), ChannelId::from_u16(2));
Source

pub fn take(&self, ordering: Ordering) -> ChannelId

Take the current channel id, leaving ChannelId::NONE in its place.

ordering describes the memory ordering of this operation. All orderings are possible, see replace for details.

§Examples
use core::sync::atomic::Ordering;

use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::new(ChannelId::from_u16(1));

assert_eq!(channel.take(Ordering::AcqRel), ChannelId::from_u16(1));
assert_eq!(channel.load(Ordering::Acquire), ChannelId::NONE);
assert_eq!(channel.take(Ordering::AcqRel), ChannelId::NONE);
Source

pub fn into_inner(self) -> ChannelId

Consume the atomic channel id, returning the contained value.

Since this takes ownership no synchronization is needed.

§Examples
use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::new(ChannelId::from_u16(1));
assert_eq!(channel.into_inner(), ChannelId::from_u16(1));

Trait Implementations§

Source§

impl Debug for AtomicChannelId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AtomicChannelId

Source§

fn default() -> Self

Construct an atomic channel id containing ChannelId::NONE.

§Examples
use core::sync::atomic::Ordering;

use musli_web::api::{AtomicChannelId, ChannelId};

let channel = AtomicChannelId::default();
assert_eq!(channel.load(Ordering::Acquire), ChannelId::NONE);
Source§

impl From<ChannelId> for AtomicChannelId

Source§

fn from(id: ChannelId) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HasAllProps<(), T> for T

Source§

impl<T> HasAllProps<(), T> for T

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more