Skip to main content

GuardCondition

Struct GuardCondition 

Source
pub struct GuardCondition<'owner> { /* private fields */ }
Expand description

A manually triggered condition for use with a WaitSet.

A GuardCondition allows application code to unblock a waiting WaitSet from another thread or in response to an external event. Set it to true to trigger attached waitsets and false to reset it.

Implementations§

Source§

impl<'o> GuardCondition<'o>

Source

pub fn new(owner: &'o dyn Entity) -> Result<Self>

Creates a new GuardCondition owned by owner.

The guard condition is valid for the lifetime of owner.

§Errors

Returns an Error if the guard condition fails to create.

§Examples
use cyclonedds::GuardCondition;

let guard_condition = GuardCondition::new(&participant)?;
Source

pub fn set(&mut self, triggered: bool) -> Result<()>

Sets the triggered state of this guard condition.

Setting to true unblocks any WaitSet this condition is attached to. Setting to false resets it.

§Errors

Returns an Error if the condition failed to set.

§Examples
use cyclonedds::GuardCondition;

let mut guard_condition = GuardCondition::new(&participant)?;
guard_condition.set(true)?;
Source

pub fn peek(&self) -> Result<bool>

Returns the current triggered state without clearing it.

Equivalent to read.

§Errors

Returns an Error if the condition failed to read.

§Examples
use cyclonedds::GuardCondition;

let mut guard = GuardCondition::new(&participant)?;
guard.set(true)?;
assert_eq!(guard.peek()?, true);
Source

pub fn read(&self) -> Result<bool>

Returns the current triggered state without clearing it.

§Errors

Returns an Error if the condition failed to read.

§Examples
use cyclonedds::GuardCondition;

let mut guard = GuardCondition::new(&participant)?;
guard.set(true)?;
assert_eq!(guard.read()?, true);
// State is preserved after read.
assert_eq!(guard.read()?, true);
Source

pub fn take(&mut self) -> Result<bool>

Returns the current triggered state and clears it.

Unlike read, this resets the triggered state to false after returning it.

§Errors

Returns an Error if the condition failed to take.

§Examples
use cyclonedds::GuardCondition;

let mut guard = GuardCondition::new(&participant)?;
guard.set(true)?;
assert_eq!(guard.take()?, true);
// State has been cleared.
assert_eq!(guard.read()?, false);

Trait Implementations§

Source§

impl<'owner> Debug for GuardCondition<'owner>

Source§

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

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

impl Drop for GuardCondition<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Entity for GuardCondition<'_>

Source§

fn id(&self) -> EntityId

Returns the EntityId of this entity. Read more
Source§

fn instance_handle(&self) -> Result<InstanceHandle>

Returns the InstanceHandle of this entity. Read more
Source§

fn status_changes(&self) -> Result<Status>

Returns the set of status flags that have changed since they were last read or taken. Read more
Source§

fn take_status(&self, mask: Option<Status>) -> Result<Status>

Takes and clears the status flags matching mask, or all flags if mask is None. Read more
Source§

fn read_status(&self, mask: Option<Status>) -> Result<Status>

Reads the status flags matching mask without clearing them, or all flags if mask is None. Read more
Source§

fn status_mask(&self) -> Result<Status>

Returns the status mask enabled on the entity. Read more
Source§

fn set_status_mask(&self, mask: Status) -> Result<()>

Sets and enables a status mask on the entity. Read more

Auto Trait Implementations§

§

impl<'owner> !RefUnwindSafe for GuardCondition<'owner>

§

impl<'owner> !Send for GuardCondition<'owner>

§

impl<'owner> !Sync for GuardCondition<'owner>

§

impl<'owner> !UnwindSafe for GuardCondition<'owner>

§

impl<'owner> Freeze for GuardCondition<'owner>

§

impl<'owner> Unpin for GuardCondition<'owner>

§

impl<'owner> UnsafeUnpin for GuardCondition<'owner>

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