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
impl OnceFlag
Sourcepub fn check_first(&self) -> bool
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.
Sourcepub fn is_triggered(&self) -> bool
pub fn is_triggered(&self) -> bool
Check if the flag has been triggered
Trait Implementations§
impl Send for OnceFlag
impl Sync for OnceFlag
Auto Trait Implementations§
impl !Freeze for OnceFlag
impl RefUnwindSafe for OnceFlag
impl Unpin for OnceFlag
impl UnsafeUnpin for OnceFlag
impl UnwindSafe for OnceFlag
Blanket Implementations§
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
Mutably borrows from an owned value. Read more