Skip to main content

Crate tonin_core

Crate tonin_core 

Source
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::AuthCtx
  • mcp — in-process MCP sidecar (second port, shared lifecycle)
  • telemetry — zero-config OTLP tracing + W3C TraceContext
  • transport — tonic/gRPC wiring helpers
  • discovery — k8s DNS-based service resolution
  • traits — capability traits (see below)
  • state — pre-wired DB + cache connections from env at boot
  • instrumented — OTel-span decorators around capability impls
  • job — background job / queue consumer surface
  • errorError + 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

Re-exports§

pub use state::State;
pub use error::Error;
pub use error::Result;

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.