Expand description
Core types and runtime for tonin services.
§When to use this crate directly
Depend on the umbrella crate tonin
in most cases — it re-exports this crate plus a curated prelude.
Reach for tonin-core directly when you want fewer transitive
deps than the umbrella, or finer-grained feature-flag control over
what gets compiled in.
§Example
use tonin_core::{Service, Result};
use tonin_core::auth::default::JwtValidator;
#[tokio::main]
async fn main() -> Result<()> {
let verifier = JwtValidator::from_env()?;
Service::new("greeter")
.with_auth(verifier)
.enable_mcp()
.handler(my_grpc_service())
.run()
.await
}
§Modules
auth— token extraction, verification,auth::AuthCtxmcp— in-process MCP sidecar (second port, shared lifecycle)telemetry— zero-config OTLP tracing + W3C TraceContexttransport— tonic/gRPC wiring helpersdiscovery— k8s DNS-based service resolutiontraits— capability traits (see below)state— pre-wired DB + cache connections from env at bootinstrumented— OTel-span decorators around capability implsjob— background job / queue consumer surfaceerror—Error+Result
§Capability traits
traits::Cache, traits::Database, traits::EventBus, and
traits::SecretStore are the interface-first surface every service
codes against. Concrete impls live in their own crates and are
selected at deploy time via tonin.toml engine = "..." — swapping
a backend is a TOML + Cargo.toml change, never a handler rewrite.
§Sample app
The canonical end-to-end example is
examples/greeter:
one proto, one main.rs, one tonin.toml.
§Sibling crates
tonin— umbrella re-export + preludetonin-client— peer-service client primitivestonin-mcp-macros—#[mcp_expose]proc-macrotonin-build—build.rshelper around tonic-build
Re-exports§
Modules§
- auth
- Authentication and authorization layer.
- discovery
- tonin-discovery: build endpoint URLs from service names.
- error
- Framework error type.
- instrumented
Instrumented<T>— the single decorator that gives every capability call a span, metric, and slow-op WARN log.- job
- Background-job entry point.
- mcp
- In-process MCP listener — real wire protocol via
rmcp. - prelude
- state
- Pre-wired DB + cache connections.
- telemetry
- Zero-config OTLP tracing + W3C TraceContext propagation.
- traits
- Capability traits services depend on.
- transport
- tonin-transport: thin wrapper around tonic’s gRPC server/client.
Structs§
- Service
- Service builder. Holds name, bind address, the tonic router being assembled, the optional auth layer, and the optional in-process MCP listener config + custom spawner.