twurst_server/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(
3    test(attr(deny(warnings))),
4    html_favicon_url = "https://raw.githubusercontent.com/helsing-ai/twurst/main/docs/img/twurst.png",
5    html_logo_url = "https://raw.githubusercontent.com/helsing-ai/twurst/main/docs/img/twurst.png"
6)]
7#![cfg_attr(docsrs, feature(doc_auto_cfg))]
8
9#[doc(hidden)]
10pub mod codegen;
11
12use axum::http::Uri;
13use axum::response::IntoResponse;
14pub use twurst_error::{TwirpError, TwirpErrorCode};
15
16/// Fallback method to be used with a Twirp router
17pub async fn twirp_fallback(uri: Uri) -> impl IntoResponse {
18    TwirpError::new(
19        TwirpErrorCode::BadRoute,
20        format!("{} is not a supported Twirp method", uri.path()),
21    )
22}
23
24/// Fallback method to be used with a gRPC router
25#[cfg(feature = "grpc")]
26pub async fn grpc_fallback(uri: Uri) -> impl IntoResponse {
27    tonic::Status::new(
28        tonic::Code::NotFound,
29        format!("{} is not a supported gRPC method", uri.path()),
30    )
31    .into_http::<axum::body::Body>()
32}