[][src]Macro uni_localservice::u_service_impl

u_service_impl!() { /* proc-macro */ }

Simplifies Service implementation

Example (see explanation below):

uni_components::define_service! {
    doc: "The service returns input increased by 42",
    name: my_service,
    kind: Kind::Get,
    input: i32,
    outputs: [
        Ok {
            code: 200,
            body: i32,
        },
        AccessDenied {
            code: 403,
        },
        NotFound {
            code: 404,
        },
        InternalErrorTryLater {
            code: 503,
        },
    ],
    path: "/my_service/v1/",
}

#[derive(Clone)]
pub struct MyStruct {
}

impl MyStruct {
    async fn exec(
        &mut self,
        input: my_service::In,
        env: (),
    ) -> my_service::Out {
        return my_service::Out::Ok(input + 42);
    }
}

uni_localservice::u_service_impl! {
    base: MyStruct,
    service: my_service,
    method: exec,
    env: (),
}

To implement predefined service (my_service) for a structure the structure (MyStructure) should have a method (exec) which

  • Has 3 parameters,
  • First parameter is &mut self,
  • Second parameter's type match service's input type
  • Return type match service's output type
  • Third parameter is env, you can keep it () or read more about env there

Then u_service_impl can be used:

  • base -- name of the structure
  • service -- name of the service
  • method -- name of the method
  • env -- environment type (keep it () if not sure)

Define env variable UNI_LOCALSERVICE_MACRO_DEBUG to have debug output