You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The #[handler] macro currently adds a Debug derive to every endpoint that it generates. This causes some issues when working with handlers that take generic arguments.
In some situations, e.g. services with shared database connections, a Default implementation is not appropriate or even possible. Based on some cursory testing, it seems like the default() method doesn't even get called. But it is very much possible that I missed something, so please let me know if a Default implementation is necessary.
To avoid a breaking change, perhaps the Default derive could only be omitted with an optional parameter to the handler macro?
Code example (if possible)
use poem::{get, handler, middleware::AddData, test::TestClient, web::Data,EndpointExt,Route};traitMyTrait:Clone + Send + Sync + 'static{fndo_something(&self) -> String;}#[derive(Clone)]structMyService;implMyTraitforMyService{fndo_something(&self) -> String{String::from("hello!")}}implDefaultforMyService{// 👈 I want to get rid of thisfndefault() -> Self{// since it does not seem to get calledunreachable!()// and having this `unreachable!` here}// makes me slightly uncomfortable.}#[handler]asyncfnhello<T:MyTrait>(Data(service):Data<&T>) -> String{
service.do_something()}#[tokio::main]asyncfnmain(){let tc = TestClient::new(Route::new().at("/",get(hello::<MyService>::default())).with(AddData::new(MyService)),);
tc.get("/").send().await.assert_text("hello!").await;}
The text was updated successfully, but these errors were encountered:
Description of the feature
The
#[handler]
macro currently adds aDebug
derive to every endpoint that it generates. This causes some issues when working with handlers that take generic arguments.In some situations, e.g. services with shared database connections, a
Default
implementation is not appropriate or even possible. Based on some cursory testing, it seems like thedefault()
method doesn't even get called. But it is very much possible that I missed something, so please let me know if aDefault
implementation is necessary.To avoid a breaking change, perhaps the
Default
derive could only be omitted with an optional parameter to thehandler
macro?Code example (if possible)
The text was updated successfully, but these errors were encountered: