pub struct Observers<I> { /* private fields */ }
Expand description
Container for observers.
This tpe also implements Observe
and therefore can be used like a single observer.
Each observer has an ObserverMode
attached which indicates when the observer will be
called.
Implementations
sourceimpl<I> Observers<I>
impl<I> Observers<I>
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new empty Observers
instance.
Example
use argmin::core::observers::Observers;
use argmin::core::IterState;
let observers: Observers<IterState<Vec<f64>, (), (), (), f64>> = Observers::new();
sourcepub fn push<OBS: Observe<I> + 'static>(
&mut self,
observer: OBS,
mode: ObserverMode
) -> &mut Self
pub fn push<OBS: Observe<I> + 'static>(
&mut self,
observer: OBS,
mode: ObserverMode
) -> &mut Self
Add another observer with a corresponding ObserverMode
.
Example
use argmin::core::observers::{Observers, ObserverMode};
use argmin::core::observers::SlogLogger;
use argmin::core::IterState;
let mut observers: Observers<IterState<Vec<f64>, (), (), (), f64>> = Observers::new();
let logger = SlogLogger::term();
observers.push(logger, ObserverMode::Always);
Trait Implementations
sourceimpl<I: State> Observe<I> for Observers<I>
impl<I: State> Observe<I> for Observers<I>
Implementing Observe
for Observers
allows to use it like a single observer. In its
implementation it will loop over all stored observers, checks if the conditions for observing
are met and calls the actual observers if required.
Auto Trait Implementations
impl<I> RefUnwindSafe for Observers<I>
impl<I> !Send for Observers<I>
impl<I> !Sync for Observers<I>
impl<I> Unpin for Observers<I>
impl<I> UnwindSafe for Observers<I>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more