January 2019
Intermediate to advanced
520 pages
14h 32m
English
In the previous section, we implemented simple services based on service_fn_ok functions, which expect the service function not to throw any errors. There are also service_fn functions, which can be used to create handlers that can return an error. These are more suitable for asynchronous Future results. As we saw previously, the Future trait has two associated types: one for a successful result and one for an error. The service_fn function expects the result to be converted into future with the IntoFuture trait. You can read more about the futures crate and its types in the next chapter.
Let's change the previous service function into one that returns the Future instance:
let server = builder.serve(|| service_fn(microservice_handler)); ...
Read now
Unlock full access