rfn
only.Expand description
Remote async functions and closures.
This module contains wrappers around async functions and closures to make them callable from a remote endpoint. Since Rust differentiates between immutable, mutable and by-value functions, remote wrappers for all three kinds of functions are provided here.
All wrappers take between zero and ten arguments, but you can use a tuple as argument if you need more than that. The arguments and return type of the function must be remote sendable.
Each wrapper spawns an async tasks that processes function execution requests from the remote endpoint.
§Usage
Create a wrapper locally and send it to a remote endpoint, for example over a
channel from the rch module.
You must use the new_n
method where n
is the number of arguments of the function.
You can also send the wrapper as part of a larger object, such as a struct, tuple
or enum.
Then use the call
method on the remote endpoint to remotely invoke the local function.
Note that the function is executed locally. Only the arguments and return value are transmitted from and to the remote endpoint.
§Return type
Since a remote function call can fail due to connection problems, the return type
of the wrapped function must always be of the Result type.
Thus your function should return a Result type with an error type that can
convert from CallError and thus absorb the remote calling error.
If you return a different type the call
method will not be available on the wrapper,
but you can still use the try_call
method, which wraps the result into a Result type.
§Cancellation
If the caller drops the future while it is executing or the connection is interrupted
the remote function is automatically cancelled at the next await
point.
§Providers
Optionally you can use the provided
method of each wrapper to obtain a
provider for each remote function wrapper.
This allows you to drop the wrapped function without relying upon the
remote endpoint for that.
This is especially useful when you connect to untrusted remote endpoints
that could try to obtain and keep a large number of remote function wrappers to
perform a denial of service attack by exhausting your memory.
§Alternatives
If you need to expose several functions remotely that operate on the same object consider remote trait calling instead.
Structs§
- Calls an async Fn function possibly located on a remote endpoint.
- Calls an async FnMut function possibly located on a remote endpoint.
- Provides a remotely callable async FnMut function.
- Calls an async FnOnce function possibly located on a remote endpoint.
- Provides a remotely callable async FnOnce function.
- Provides a remotely callable async Fn function.
Enums§
- An error occurred during calling a remote function.