behaviortree 0.8.0

A #![no_std] compatible behavior tree library similar to BehaviorTree.CPP.
Documentation
// Copyright © 2026 Stephan Kunz
//! [`behaviortree`](crate) errors.

use alloc::boxed::Box;

/// `behaviortree` error type
pub struct Error {
	/// Module name
	module: &'static str,
	/// Original error
	source: Box<dyn core::error::Error>,
}

/// Only a source implementation needed.
impl core::error::Error for Error {
	fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
		Some(self.source.as_ref())
	}
}

impl core::fmt::Debug for Error {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		write!(f, "Behaviortree(module: {}, error: {}", self.module, self.source)
	}
}

impl core::fmt::Display for Error {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		write!(f, "Behaviortree module '{}' failed with: {}", self.module, self.source)
	}
}

impl From<behaviortree_core::error::Error> for Error {
	fn from(source: behaviortree_core::error::Error) -> Self {
		Self {
			module: "core",
			source: Box::new(source),
		}
	}
}

impl From<behaviortree_core::tree::error::Error> for Error {
	fn from(source: behaviortree_core::tree::error::Error) -> Self {
		Self {
			module: "core::tree",
			source: Box::new(source),
		}
	}
}

impl From<behaviortree_factory::error::Error> for Error {
	fn from(source: behaviortree_factory::error::Error) -> Self {
		Self {
			module: "factory",
			source: Box::new(source),
		}
	}
}
impl From<databoard::Error> for Error {
	fn from(source: databoard::Error) -> Self {
		Self {
			module: "databoard",
			source: Box::new(source),
		}
	}
}

impl From<dataport::Error> for Error {
	fn from(source: dataport::Error) -> Self {
		Self {
			module: "dataport",
			source: Box::new(source),
		}
	}
}

impl From<woxml::Error> for Error {
	fn from(source: woxml::Error) -> Self {
		Self {
			module: "woxml",
			source: Box::new(source),
		}
	}
}

#[cfg(feature = "std")]
impl From<std::io::Error> for Error {
	fn from(source: std::io::Error) -> Self {
		Self {
			module: "std::io",
			source: Box::new(source),
		}
	}
}