Trait server_fn::ServerFn

source ·
pub trait ServerFn<T: 'static>
where Self: Serialize + DeserializeOwned + Sized + 'static,
{ type Output: Serialize; // Required methods fn prefix() -> &'static str; fn url() -> &'static str; fn encoding() -> Encoding; fn call_fn( self, cx: T ) -> Pin<Box<dyn Future<Output = Result<Self::Output, ServerFnError>>>>; fn call_fn_client( self, cx: T ) -> Pin<Box<dyn Future<Output = Result<Self::Output, ServerFnError>>>>; // Provided methods fn call_from_bytes( cx: T, data: &[u8] ) -> Pin<Box<dyn Future<Output = Result<Payload, ServerFnError>>>> { ... } fn register_in_explicit<R: ServerFunctionRegistry<T>>( ) -> Result<(), ServerFnError> { ... } }
Expand description

Defines a “server function.” A server function can be called from the server or the client, but the body of its code will only be run on the server, i.e., if a crate feature ssr (server-side-rendering) is enabled.

Server functions are created using the server macro.

The set of server functions can be queried on the server for routing purposes by calling server_fn_by_path.

Technically, the trait is implemented on a type that describes the server function’s arguments.

Required Associated Types§

source

type Output: Serialize

The return type of the function.

Required Methods§

source

fn prefix() -> &'static str

URL prefix that should be prepended by the client to the generated URL.

source

fn url() -> &'static str

The path at which the server function can be reached on the server.

source

fn encoding() -> Encoding

The path at which the server function can be reached on the server.

source

fn call_fn( self, cx: T ) -> Pin<Box<dyn Future<Output = Result<Self::Output, ServerFnError>>>>

Runs the function on the server.

source

fn call_fn_client( self, cx: T ) -> Pin<Box<dyn Future<Output = Result<Self::Output, ServerFnError>>>>

Runs the function on the client by sending an HTTP request to the server.

Provided Methods§

source

fn call_from_bytes( cx: T, data: &[u8] ) -> Pin<Box<dyn Future<Output = Result<Payload, ServerFnError>>>>

Returns a trait object that can be used to call the server function.

source

fn register_in_explicit<R: ServerFunctionRegistry<T>>( ) -> Result<(), ServerFnError>

Registers the server function explicitly on platforms that require it, allowing the server to query it by URL.

Object Safety§

This trait is not object safe.

Implementors§