Skip to content

feat(net-core): composition primitives#14

Merged
NotAProfDev merged 1 commit into
mainfrom
feat/net-core-composition-primitives
May 25, 2026
Merged

feat(net-core): composition primitives#14
NotAProfDev merged 1 commit into
mainfrom
feat/net-core-composition-primitives

Conversation

@NotAProfDev
Copy link
Copy Markdown
Owner

Closes #12

Summary

Implements the zero-runtime composition primitives for oath-net-core — the foundation every other network crate builds on.

Changes

Cargo.toml (root)

Added five new workspace dependencies required by net-core:
bytes, http, http-body, futures-core, futures-sink

crates/net/core/Cargo.toml

Wired the five workspace deps. No tokio, hyper, serde, or thiserror — the zero-runtime constraint is preserved.

crates/net/core/src/service.rs (new)

  • Service<Req> trait — RPITIT return type, &self receiver, no poll_ready
  • Layer<S> trait — wraps one service into another
  • ServiceBuilder<L> — compile-time compositor; first .layer() call is permanently outermost; derives Clone; layer() is #[must_use]
  • Identity — no-op layer; termination case for the Stack recursion
  • Stack<Inner, Outer> — composes two layers; Inner applied first (closer to leaf), Outer executes first on requests

crates/net/core/src/error_kind.rs (new)

  • ErrorKind — coarse middleware routing enum (Timeout, Connection, Throttled, Auth, Client, Server, Unknown); #[non_exhaustive]
  • HasErrorKind — implemented by backend error types so middleware layers can branch without inspecting concrete types

crates/net/core/src/lib.rs

Updated with module declarations and pub use re-exports for all public types.

Design decisions

  • No Send + Sync supertrait on Service — kept general so test doubles, single-threaded adapters, and WASM targets can implement the trait; call sites that require thread-safety add their own bounds
  • No async fn in traits — RPITIT (fn → impl Future + Send) avoids async-trait, boxing, and per-call allocation
  • No dyn anywhere — entire stack resolves to a single monomorphized type at compile time; zero virtual dispatch on the hot path

- Add workspace deps: bytes, http, http-body, futures-core, futures-sink
- Wire crates/net/core/Cargo.toml with those deps (zero runtime deps)
- Implement service.rs: Service, Layer, ServiceBuilder, Identity, Stack
- Implement error_kind.rs: ErrorKind, HasErrorKind
- Update lib.rs: module declarations and pub re-exports
- ServiceBuilder derives Clone; layer() is #[must_use]
@NotAProfDev NotAProfDev merged commit 71f5fc2 into main May 25, 2026
2 checks passed
@NotAProfDev NotAProfDev deleted the feat/net-core-composition-primitives branch May 25, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(net-core): composition primitives

1 participant