pub struct AtomicChannelId { /* private fields */ }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
impl AtomicChannelId
Sourcepub const NONE: Self
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);Sourcepub const fn new(id: ChannelId) -> Self
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));Sourcepub fn load(&self, ordering: Ordering) -> ChannelId
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));Sourcepub fn store(&self, id: ChannelId, ordering: Ordering)
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));Sourcepub fn replace(&self, id: ChannelId, ordering: Ordering) -> ChannelId
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));Sourcepub fn take(&self, ordering: Ordering) -> ChannelId
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);Sourcepub fn into_inner(self) -> ChannelId
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
impl Debug for AtomicChannelId
Source§impl Default for AtomicChannelId
impl Default for AtomicChannelId
Source§fn default() -> Self
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);Auto Trait Implementations§
impl !Freeze for AtomicChannelId
impl RefUnwindSafe for AtomicChannelId
impl Send for AtomicChannelId
impl Sync for AtomicChannelId
impl Unpin for AtomicChannelId
impl UnsafeUnpin for AtomicChannelId
impl UnwindSafe for AtomicChannelId
Blanket Implementations§
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> HasAllProps<(), T> for T
impl<T> HasAllProps<(), T> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.