Skip to main content

bonsai_mdsl/
lib.rs

1//! # Bonsai MDSL
2//!
3//! A Rust library for parsing and executing behavior trees defined in MDSL (Mistreevous Domain Specific Language).
4//!
5//! This library provides a high-performance, type-safe implementation of behavior trees using the MDSL format
6//! originally created by the [mistreevous](https://github.com/nikkorn/mistreevous) TypeScript library.
7//!
8//! ## Basic Usage
9//!
10//! ```rust
11//! use bonsai_mdsl::{BehaviorTree, TreeContext, NodeResult};
12//!
13//! let mdsl = r#"
14//! root {
15//!     sequence {
16//!         action [greet]
17//!         action [wave]
18//!     }
19//! }
20//! "#;
21//!
22//! let mut context = TreeContext::new();
23//! context.register_simple_action("greet", || {
24//!     println!("Hello!");
25//!     NodeResult::Success
26//! });
27//! context.register_simple_action("wave", || {
28//!     println!("*waves*");
29//!     NodeResult::Success
30//! });
31//!
32//! let mut tree = BehaviorTree::from_mdsl(mdsl).unwrap();
33//! let result = tree.tick(&context).unwrap();
34//! assert_eq!(result, NodeResult::Success);
35//! ```
36
37pub mod context;
38pub mod error;
39pub mod nodes;
40pub mod parser;
41pub mod tree;
42
43#[cfg(feature = "async")]
44pub mod async_context;
45
46// Re-export the main types for convenience
47pub use context::TreeContext;
48pub use error::{BonsaiError, Result};
49pub use nodes::{Node, NodeResult, NodeState, NodeType};
50pub use tree::BehaviorTree;
51
52// Async context is currently unused - async behavior trees work well with external task management
53// as demonstrated in the async_drone example using channels and tokio::spawn
54#[cfg(feature = "async")]
55pub use async_context::AsyncTreeContext;
56
57// Re-export parser utilities
58pub use parser::{parse_mdsl, MdslValue};
59
60/// Current version of the library
61pub const VERSION: &str = env!("CARGO_PKG_VERSION");