camel-bean-macros 0.56.0

Proc-macros for camel-bean crate
Documentation
1
impl OrderService { # [handler] pub async fn process (& self , body : String) -> Result < String , String > { Ok (body) } # [handler] pub async fn notify (& self) { } } # [:: camel_bean :: async_trait] impl :: camel_bean :: BeanProcessor for OrderService { async fn call (& self , method : & str , exchange : & mut :: camel_api :: Exchange ,) -> Result < () , :: camel_api :: CamelError > { match method { "process" => { let body : String = match & exchange . input . body { :: camel_api :: Body :: Json (value) => { :: serde_json :: from_value (value . clone ()) . map_err (| e | :: camel_api :: CamelError :: TypeConversionFailed (format ! ("Failed to deserialize body: {}" , e))) ? } :: camel_api :: Body :: Text (s) => s . clone () , other => return Err (:: camel_api :: CamelError :: TypeConversionFailed (format ! ("Expected JSON or text body, got {:?}" , other))) , } ; let result = self . process (body) . await ; let value = result . map_err (| e | :: camel_api :: CamelError :: ProcessorError (e . to_string ())) ? ; exchange . input . body = :: camel_api :: Body :: Json (:: serde_json :: to_value (value) . map_err (| e | :: camel_api :: CamelError :: TypeConversionFailed (format ! ("Failed to serialize result: {}" , e))) ?) ; Ok (()) } "notify" => { let result = self . notify () . await ; result . map_err (| e | :: camel_api :: CamelError :: ProcessorError (e . to_string ())) ? ; Ok (()) } _ => Err (:: camel_api :: CamelError :: ProcessorError (format ! ("Method '{}' not found" , method))) } } fn methods (& self) -> Vec < String > { vec ! ["process" . to_string () , "notify" . to_string ()] } }