Skip to main content

OnceFlag

Struct OnceFlag 

Source
pub struct OnceFlag { /* private fields */ }
Expand description

A flag for tracking one-time logging

Use this with Logger::*_once() or Logger::*_skip_first() methods to control conditional logging. The flag should be declared as a static to ensure it persists across calls.

§Example

use nros_core::{Logger, OnceFlag};

static LOGGED: OnceFlag = OnceFlag::new();
let logger = Logger::new("my_node");

// Only the first call will actually log
for _ in 0..10 {
    logger.info_once(&LOGGED, "This only logs once");
}

Implementations§

Source§

impl OnceFlag

Source

pub const fn new() -> Self

Create a new once flag (not yet triggered)

Source

pub fn check_first(&self) -> bool

Check if this is the first time being called, and mark as triggered

Returns true on the first call, false on subsequent calls.

Uses load+store instead of compare_exchange for compatibility with targets lacking CAS (e.g., riscv32imc without the A extension). This is safe for nros’s single-core embedded use cases.

Source

pub fn is_triggered(&self) -> bool

Check if the flag has been triggered

Source

pub fn reset(&self)

Reset the flag to untriggered state

Trait Implementations§

Source§

impl Debug for OnceFlag

Source§

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

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

impl Default for OnceFlag

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Send for OnceFlag

Source§

impl Sync for OnceFlag

Auto Trait Implementations§

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.