Skip to content

Commit

Permalink
share inventory collect across types
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj committed Jan 19, 2024
1 parent 9855bc5 commit 62298db
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions server_fn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ impl<Req, Res> Clone for ServerFnTraitObj<Req, Res> {
type LazyServerFnMap<Req, Res> =
Lazy<DashMap<&'static str, ServerFnTraitObj<Req, Res>>>;

#[cfg(feature = "ssr")]
impl<Req: 'static, Res: 'static> inventory::Collect
for ServerFnTraitObj<Req, Res>
{
#[inline]
fn registry() -> &'static inventory::Registry {
static REGISTRY: inventory::Registry = inventory::Registry::new();
&REGISTRY
}
}

/// Axum integration.
#[cfg(feature = "axum")]
pub mod axum {
Expand All @@ -453,8 +464,6 @@ pub mod axum {
use axum::body::Body;
use http::{Method, Request, Response, StatusCode};

inventory::collect!(ServerFnTraitObj<Request<Body>, Response<Body>>);

static REGISTERED_SERVER_FUNCTIONS: LazyServerFnMap<
Request<Body>,
Response<Body>,
Expand Down Expand Up @@ -539,8 +548,6 @@ pub mod actix {
#[doc(hidden)]
pub use send_wrapper::SendWrapper;

inventory::collect!(ServerFnTraitObj<ActixRequest, ActixResponse>);

static REGISTERED_SERVER_FUNCTIONS: LazyServerFnMap<
ActixRequest,
ActixResponse,
Expand Down

0 comments on commit 62298db

Please sign in to comment.