llmkit_tower/layer.rs
1//! The [`LlmLayer`] trait: a Tower-style decorator over [`LlmProvider`].
2
3use std::sync::Arc;
4
5use llmkit_core::LlmProvider;
6
7/// Wraps an inner [`LlmProvider`] in a new one, adding cross-cutting behaviour.
8///
9/// Analogous to `tower::Layer`, but specialised to the LLM provider trait so
10/// that wrapped providers remain `LlmProvider`s — no `Service<Request>` generic
11/// gymnastics or sprawling `where` clauses. Each layer's output is itself a
12/// provider, so layers compose freely and the result is a single
13/// `Arc<dyn LlmProvider>`.
14pub trait LlmLayer {
15 /// The provider produced by wrapping `inner`.
16 type Provider: LlmProvider;
17
18 /// Wrap `inner`, returning the decorated provider.
19 fn layer(self, inner: Arc<dyn LlmProvider>) -> Self::Provider;
20}