Make macro system and PTY test leaf

This commit is contained in:
Michael Mikovsky
2026-05-28 18:17:01 -06:00
parent aeffe8b8ec
commit fc82f4f921
23 changed files with 1866 additions and 86 deletions
+3 -54
View File
@@ -12,62 +12,11 @@
#![no_std]
pub extern crate alloc;
// Re-export derive macros against a stable `::unshell` path, including when the
// macros are used inside this crate's own examples and tests.
#[allow(unused_extern_crates)]
extern crate self as unshell;
pub mod logger;
/// Re-export the protocol crate behind the historical `unshell::protocol` path so
/// proc-macro output and downstream code do not need a second migration.
pub use unshell_protocol as protocol;
pub mod protocol {
pub use unshell_protocol::*;
// Re-export the leaf library crate behind the historical `unshell::leaves` path
// once the leaf crate is part of the active workspace again.
// pub use unshell_leaves as leaves;
// Re-export the runtime crate behind the `unshell::runtime` path once the runtime
// crate is part of the active workspace again.
// pub use unshell_runtime as runtime;
// pub use unshell_macros::{Procedure, leaf, procedures};
/// Creates a root-assumed endpoint from one local identifier plus any number of leaf hosts.
///
/// What it is: a convenience macro that builds a `ProtocolEndpoint` whose protocol path starts at
/// root, with no parent or children, and whose leaf inventory is inferred from the supplied host
/// values.
///
/// Why it exists: the common bootstrap case should not require callers to manually construct an
/// empty path, `Vec<ChildRoute>`, and a `Vec<LeafSpec>` when they already have leaf host values.
///
/// # Example
///
/// ```rust,ignore
/// use unshell::{create_endpoint, leaf};
/// use unshell::protocol::tree::Endpoint;
///
/// #[derive(Default)]
/// struct DemoLeaf;
///
/// #[leaf(id = "org.example.v1.demo", procedures = ["ping"], endpoint_struct = DemoLeaf)]
/// struct Demo;
///
/// let endpoint = create_endpoint!("demo", DemoLeaf::default());
/// assert!(endpoint.path().is_empty());
/// assert_eq!(endpoint.local_id(), Some("demo"));
/// ```
#[macro_export]
macro_rules! create_endpoint {
($id:expr $(, $leaf:expr )* $(,)?) => {{
let mut __unshell_leaf_specs = ::unshell::alloc::vec::Vec::new();
$(
let __unshell_leaf = $leaf;
__unshell_leaf_specs.push(::unshell::protocol::tree::leaf_spec_of(&__unshell_leaf));
)*
::unshell::protocol::tree::ProtocolEndpoint::root($id, __unshell_leaf_specs)
}};
pub use unshell_macros::unshell_leaf;
}
// pub use ush_obfuscate as obfuscate;