Skip to main content

Visitor

Trait Visitor 

Source
pub trait Visitor {
    // Required method
    fn leaf(
        &mut self,
        path: &str,
        array: &Array,
        kind: LeafKind,
        trainable: bool,
    );

    // Provided methods
    fn paths(&self) -> bool { ... }
    fn enter(&mut self, path: &str, name: &str, type_name: &'static str) { ... }
    fn exit(&mut self, path: &str) { ... }
    fn variant(&mut self, path: &str, index: u32) { ... }
    fn mode(&mut self, path: &str, training: bool) { ... }
    fn static_field(&mut self, path: &str, value: &dyn Static) { ... }
}
Expand description

Receives what a Visit reports, with full paths. Every method but Visitor::leaf has an empty default.

Required Methods§

Source

fn leaf(&mut self, path: &str, array: &Array, kind: LeafKind, trainable: bool)

A leaf: its array, kind and whether it is trainable.

Provided Methods§

Source

fn paths(&self) -> bool

Whether the visitor reads paths (true by default); without them, every path it receives is empty and the visit builds none (faster).

Source

fn enter(&mut self, path: &str, name: &str, type_name: &'static str)

A child tree of type type_name starts at path (name is its own segment; empty for transparent wrappers such as Option).

Source

fn exit(&mut self, path: &str)

The child tree entered last at path ends.

Source

fn variant(&mut self, path: &str, index: u32)

An enum’s active variant (or Option’s: 0 for None, 1 for Some).

Source

fn mode(&mut self, path: &str, training: bool)

A mode flag (train/eval).

Source

fn static_field(&mut self, path: &str, value: &dyn Static)

A static field (a hashed #[tree(skip)] field).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§