hexkit 0.1.0

Lightweight boundary traits for hexagonal architecture in Rust
Documentation
  • Coverage
  • 100%
    14 out of 14 items documented1 out of 1 items with examples
  • Size
  • Source code size: 48.99 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.16 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • RAV64/hexkit
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • RAV64

hexkit

Small boundary traits for hexagonal architecture in Rust.

What This Crate Provides

  • Handle<I>: immutable/read-style interaction boundary.
  • HandleMut<I>: mutable/write-style interaction boundary.
  • Optional async equivalents in hexkit::r#async behind feature flag async.

You define your own interaction input/output types and adapters.

Hello World

use hexkit::{Handle, HandleMut};

struct CreateUser {
    name: String,
}

struct ReadUser {
    id: u64,
}

#[derive(Default)]
struct UserCore {
    next_id: u64,
    rows: Vec<(u64, String)>,
}

impl HandleMut<CreateUser> for UserCore {
    type Output<'a> = u64;

    fn handle_mut(&mut self, input: CreateUser) -> Self::Output<'_> {
        self.next_id += 1;
        self.rows.push((self.next_id, input.name));
        self.next_id
    }
}

impl Handle<ReadUser> for UserCore {
    type Output<'a> = Option<&'a str>;

    fn handle(&self, input: ReadUser) -> Self::Output<'_> {
        self.rows
            .iter()
            .find(|(id, _)| *id == input.id)
            .map(|(_, name)| name.as_str())
    }
}

fn main() {
    let mut core = UserCore::default();
    let id = core.handle_mut(CreateUser { name: String::from("lea") });
    let name = core.handle(ReadUser { id }).expect("user should exist");
    assert_eq!(name, "lea");
}

Async

Enable the feature:

[dependencies]
hexkit = { version = "0.1", features = ["async"] }

Use:

use hexkit::r#async::{Handle, HandleMut};

Examples

See examples/README.md for an example map.

Quick start commands:

  • cargo run --example sync_basic_in_memory
  • cargo run --example canonical_app_skeleton
  • cargo run --example async_basic_email_flow --features async