Skip to main content

Module native

Module native 

Source
Expand description

§Native Async Port Traits

Ergonomic native async fn trait alternatives that don’t require #[async_trait]. Developers implement these for the best IDE experience and fastest compile times. The framework automatically bridges them to the dyn-compatible ports via blanket implementations.

§Why Two Sets of Traits?

Rust’s native async fn in trait (RPITIT) produces opaque impl Future return types, which are not object-safe. The framework’s runtime uses Arc<dyn Port> for flexibility, requiring #[async_trait] (which boxes the future). These native traits let you write clean code without the macro overhead, while the blanket impls handle the bridging.

§Example

use bob_core::native::NativeLlmPort;

struct MyLlm;

// Native async — no #[async_trait] needed
impl NativeLlmPort for MyLlm {
    async fn complete(&self, req: LlmRequest) -> Result<LlmResponse, LlmError> {
        // ...
    }
}

// Automatically usable as Arc<dyn LlmPort> via blanket impl
let port: Arc<dyn LlmPort> = Arc::new(MyLlm);

Traits§

NativeLlmPort
Native async LLM port — implement this for the cleanest developer experience.
NativeSessionStore
Native async session store — implement this for the cleanest developer experience.
NativeToolPort
Native async tool port — implement this for the cleanest developer experience.