Skip to main content

Module templates

Module templates 

Source
Expand description

Template framework for quickly scaffolding hexser components.

This module provides lightweight helpers and macros that REGISTER your components without relying on derive macros: each one emits the Registrable impl AND the inventory::submit! that puts the type in HexGraph::current(). It complements proc-macro derives by offering simple, explicit building blocks you can use in any context (including no-macros builds).

⚠ BOTH HALVES ARE THE REGISTRATION. HexGraph::current() is built by iterating the inventory registry, so a Registrable impl on its own yields a type that answers node_info() correctly and is in NO graph. These macros emitted only the impl until 2026-09-04: the crate had no non-derive door into the graph at all, while naming these hex_register_*.

Registration is an ITEM-scope act — the submission is a static discovered at link time — so invoke these macros at module scope, next to the type, not inside a function body.

§Quick examples

use hexser::prelude::*;

struct MyEntity { id: u64 }

// Register a domain Entity using a template macro (module scope, next to the type).
hexser::hex_register_domain!(MyEntity, Role::Entity);

fn main() {
  // The type answers node_info() AND is in the process-wide graph.
  let info = <MyEntity as Registrable>::node_info();
  assert_eq!(info.layer, Layer::Domain);
  assert_eq!(info.role, Role::Entity);
  assert!(
    hexser::HexGraph::current()
      .nodes()
      .any(|n| n.type_name().ends_with("MyEntity"))
  );
}
use hexser::prelude::*;

struct PgUserRepo;

// Register as an Adapter implementing a Repository.
hexser::hex_register_adapter!(PgUserRepo, Role::Adapter);

fn main() {
  assert_eq!(
    <PgUserRepo as Registrable>::node_info().layer,
    Layer::Adapter
  );
}

These helpers are intended as templates: copy, adapt, and extend as needed.

Revision History

  • 2026-09-11T00:00:00Z @AI: Allow needless_doctest_main — the explicit fn main is what keeps the macro invocations at module scope, which is the whole subject of these examples.
  • 2026-09-04T00:00:00Z @AI: The hex_register_* macros now emit the inventory submission they are named for. They implemented Registrable and never submitted, so every type “registered” through hexser’s own explicit path answered node_info() correctly and was absent from every graph query — the same end state as the silently-omitted generic submission, reached through the door the crate advertises.

Functions§

split_type_name
Split a fully-qualified Rust type path into (module_path, type_name).