MCPcopy Create free account
hub / github.com/HFQR/xitca-web / error

Function error

codegen/src/error.rs:5–32  ·  view source on GitHub ↗
(_: TokenStream, item: ItemImpl)

Source from the content-addressed store, hash-verified

3use syn::{Error, ItemImpl, Type, spanned::Spanned};
4
5pub(crate) fn error(_: TokenStream, item: ItemImpl) -> Result<TokenStream, Error> {
6 let Type::Path(ref err_ty) = *item.self_ty else {
7 return Err(Error::new(item.self_ty.span(), "expect Struct or Enum"));
8 };
9
10 let call_impl = crate::find_async_method(&item.items, "call")
11 .ok_or_else(|| Error::new(err_ty.span(), "expect 'async fn call' method"))??;
12
13 let call_stmts = &call_impl.block.stmts;
14
15 Ok(quote! {
16 impl<'r> ::xitca_web::service::Service<WebContext<'r, ::xitca_web::error::Request<'r>>> for #err_ty {
17 type Response = WebResponse;
18 type Error = ::core::convert::Infallible;
19
20 async fn call(&self, ctx: WebContext<'r, ::xitca_web::error::Request<'r>>) -> Result<Self::Response, Self::Error> {
21 Ok({#(#call_stmts)*})
22 }
23 }
24
25 impl From<#err_ty> for ::xitca_web::error::Error {
26 fn from(e: #err_ty) -> Self {
27 Self::from_service(e)
28 }
29 }
30 }
31 .into())
32}

Callers 3

mainFunction · 0.85
erase_errorFunction · 0.85
error_implFunction · 0.85

Calls 1

find_async_methodFunction · 0.85

Tested by 1

erase_errorFunction · 0.68