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§
Required Methods§
sourcefn prefix() -> &'static str
fn prefix() -> &'static str
URL prefix that should be prepended by the client to the generated URL.
sourcefn call_fn(
self,
cx: T
) -> Pin<Box<dyn Future<Output = Result<Self::Output, ServerFnError>>>>
fn call_fn( self, cx: T ) -> Pin<Box<dyn Future<Output = Result<Self::Output, ServerFnError>>>>
Runs the function on the server.
sourcefn call_fn_client(
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>>>>
Runs the function on the client by sending an HTTP request to the server.
Provided Methods§
sourcefn call_from_bytes(
cx: T,
data: &[u8]
) -> Pin<Box<dyn Future<Output = Result<Payload, ServerFnError>>>>
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.
sourcefn register_in_explicit<R: ServerFunctionRegistry<T>>(
) -> Result<(), ServerFnError>
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.