Skip to main content

Module mount

Module mount 

Source
Expand description

Builder-style API composition with .mount().

For APIs larger than 25 endpoints, or when you want to compose sub-APIs incrementally, the mount builder provides a flat, readable alternative to nested tuples.

§Example

type UsersAPI = (GetEndpoint<UsersPath, Vec<User>>, PostEndpoint<UsersPath, CreateUser, User>);
type OrdersAPI = (GetEndpoint<OrdersPath, Vec<Order>>,);
type FullAPI = (UsersAPI, OrdersAPI);

ServerBuilder::<FullAPI>::new()
    .mount::<UsersAPI>((bind!(list_users), bind!(create_user)))
    .mount::<OrdersAPI>((bind!(list_orders),))
    .build()
    .serve("0.0.0.0:3000".parse()?)
    .await?;

Each .mount() call registers a sub-API’s handlers into the router. .build() requires all sub-APIs in the full API type to have been mounted — missing a mount is a compile error.

Structs§

LayeredServerBuilder
A ServerBuilder with Tower middleware layers applied.
MCons
Type-level cons: sub-API A has been mounted, followed by Tail.
MHere
Type-level proof that a sub-API has been mounted.
MNil
Type-level empty list: no sub-APIs mounted yet.
MThere
Type-level index: the sub-API is somewhere later in the list.
ServerBuilder
A builder for composing large APIs from sub-APIs.

Traits§

AllMounted
Asserts that ALL sub-APIs in FullAPI have been mounted.
HasMount
Asserts that sub-API A is in the mounted list M.