kiwi_sdk/
lib.rs

1//! # Kiwi SDK
2//! This crate provides utilities necessary for writing [Kiwi](https://github.com/rkrishn7/kiwi) plugins.
3//!
4//! # Examples
5//!
6//! ## Intercept
7//! ```ignore
8//! //! A simple intercept hook that discards odd numbers from all counter sources
9//! use kiwi_sdk::hook::intercept::{intercept, Action, Context, CounterEventCtx, EventCtx};
10//!
11//! /// You must use the `#[intercept]` macro to define an intercept hook.
12//! #[intercept]
13//! fn handle(ctx: Context) -> Action {
14//!     match ctx.event {
15//!         // We only care about counter sources in this example
16//!         EventCtx::Counter(CounterEventCtx {
17//!             source_id: _,
18//!             count,
19//!         }) => {
20//!             if count % 2 == 0 {
21//!                 // Returning `Action::Forward` instructs Kiwi to forward the event
22//!                 // to the associated client.
23//!                 return Action::Forward;
24//!             } else {
25//!                 // Returning `Action::Discard` instructs Kiwi to discard the event,
26//!                 // preventing it from reaching the associated client.
27//!                 return Action::Discard;
28//!             }
29//!         }
30//!         _ => {}
31//!     }
32//!
33//!     Action::Forward
34//! }
35//! ```
36//!
37//! ## Authenticate
38//! ```ignore
39//! //! A simple authenticate hook that allows all incoming HTTP requests
40//! use kiwi_sdk::hook::authenticate::{authenticate, Outcome};
41//! use kiwi_sdk::http::Request;
42//!
43//! /// You must use the `#[authenticate]` macro to define an authenticate hook.
44//! #[authenticate]
45//! fn handle(req: Request<()>) -> Outcome {
46//!     // Returning `Outcome::Authenticate` instructs Kiwi to allow the connection to be established.
47//!     Outcome::Authenticate
48//! }
49//! ```
50
51pub mod hook;
52
53#[doc(hidden)]
54pub mod wit {
55    #![allow(missing_docs)]
56    #![allow(clippy::missing_safety_doc)]
57    #![allow(clippy::transmute_int_to_bool)]
58
59    wit_bindgen::generate!({
60        path: "./wit",
61        world: "internal",
62    });
63}
64
65/// Re-export for macro use.
66#[doc(hidden)]
67pub use wit_bindgen;
68
69pub mod http;