Skip to main content

Callback

Trait Callback 

Source
pub trait Callback: Send {
    // Provided methods
    fn on_begin(&mut self, _ctx: &dyn IteratorContext) { ... }
    fn on_step(&mut self, _ctx: &dyn IteratorContext) { ... }
    fn on_end(&mut self, _ctx: &dyn IteratorContext) { ... }
}
Expand description

Keras-style hook interface for OA iterator sessions.

Attach one or more callbacks to a session via its add_callback method. All hooks receive a &dyn IteratorContext so callbacks stay decoupled from the concrete session type.

§Mapping from C++

C++Rust
onBegin(Iterator&)on_begin(&mut self, ctx)
onStep(Iterator&)on_step(&mut self, ctx)
onEnd(Iterator&)on_end(&mut self, ctx)

C++ used virtual inheritance; Rust uses dynamic dispatch through Box<dyn Callback>. The C++ move-constructor convention maps to Rust’s normal ownership — place Box<dyn Callback> values in a Vec rather than raw pointers.

Provided Methods§

Source

fn on_begin(&mut self, _ctx: &dyn IteratorContext)

Fired once before the first step.

Source

fn on_step(&mut self, _ctx: &dyn IteratorContext)

Fired after each step. The iterator has already advanced to ctx.index().

Source

fn on_end(&mut self, _ctx: &dyn IteratorContext)

Fired once after the last step or when the session is explicitly finished.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§