Struct base::Event

source ·
pub struct Event(pub(crate) PlatformEvent);
Expand description

An inter-process event wait/notify mechanism. Loosely speaking: Writes signal the event. Reads block until the event is signaled and then clear the signal.

Supports multiple simultaneous writers (i.e. signalers) but only one simultaneous reader (i.e. waiter). The behavior of multiple readers is undefined in cross platform code.

Multiple Events can be polled at once via WaitContext.

Implementation notes:

  • Uses eventfd on Linux.
  • Uses synchapi event objects on Windows.
  • The Event and WaitContext APIs together cannot easily be implemented with the same semantics on all platforms. In particular, it is difficult to support multiple readers, so only a single reader is allowed for now. Multiple readers will result in undefined behavior.

Tuple Fields§

§0: PlatformEvent

Implementations§

source§

impl Event

source

pub fn new() -> Result<Event>

Creates new event in an unsignaled state.

source

pub fn signal(&self) -> Result<()>

Signals the event.

source

pub fn wait(&self) -> Result<()>

Blocks until the event is signaled and clears the signal.

It is undefined behavior to wait on an event from multiple threads or processes simultaneously.

source

pub fn wait_timeout(&self, timeout: Duration) -> Result<EventWaitResult>

Blocks until the event is signaled and clears the signal, or until the timeout duration expires.

It is undefined behavior to wait on an event from multiple threads or processes simultaneously.

source

pub fn reset(&self) -> Result<()>

Clears the event without blocking.

If the event is not signaled, this has no effect and returns immediately.

source

pub fn try_clone(&self) -> Result<Event>

Clones the event. The event’s state is shared between cloned instances.

The documented caveats for Event also apply to a set of cloned instances, e.g., it is undefined behavior to clone an event and then call Event::wait simultaneously on both objects.

Implementation notes:

  • Linux: The cloned instance uses a separate file descriptor.
  • Windows: The cloned instance uses a separate handle.

Trait Implementations§

source§

impl AsRawDescriptor for Event

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more
source§

impl Debug for Event

source§

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

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

impl<'de> Deserialize<'de> for Event

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl EventExt for Event

source§

fn write_count(&self, v: u64) -> Result<()>

Adds v to the eventfd’s count, blocking until this won’t overflow the count.
source§

fn read_count(&self) -> Result<u64>

Blocks until the the eventfd’s count is non-zero, then resets the count to zero.
source§

impl From<Event> for SafeDescriptor

source§

fn from(evt: Event) -> Self

Converts to this type from the input type.
source§

impl From<SafeDescriptor> for Event

source§

fn from(sd: SafeDescriptor) -> Self

Converts to this type from the input type.
source§

impl FromRawDescriptor for Event

source§

unsafe fn from_raw_descriptor(descriptor: RawDescriptor) -> Self

Safety Read more
source§

impl IntoRawDescriptor for Event

source§

impl PartialEq for Event

source§

fn eq(&self, other: &Event) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Event

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Event

source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

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> AsRawDescriptors for T
where T: AsRawDescriptor,

source§

fn as_raw_descriptors(&self) -> Vec<i32>

Returns the underlying raw descriptors. 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>,

§

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>,

§

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,