2 stable releases

1.0.1 Nov 25, 2023

#6 in #inheritance


Used in agera

MIT/Apache

21KB
413 lines

OOP inheritance

Flexible object-oriented Nodes that can be subclassed for the Rust language. See the API reference for full details.


lib.rs:

This crate provides object-oriented inheritance using Nodes.

A Node consits of a set of components and a Node can have other children nodes.

Defining classes

Use the class! invocation for defining class.

Components

use oop_inheritance::*;

let something = Node::new();

// Set a component
something.set::<f64>(10);

// `Option<Arc<f64>>`
something.get::<f64>();

Children

something.add_child(&another_thing);

Node paths

Since Nodes are in hierarchy, every Node that has a name may be found when using the .resolve_path method. However, there are special segments of an Node path that do not resolve by name, which may be useful in some contexts:

  • .first resolves to the first child of an Node;
  • .last resolves to the last child of an Node;
  • .. resolves to the parent.
let last_sibling: Option<Node> = node.resolve_path("../.last");

Dependencies

~305–760KB
~18K SLoC