mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
chore(server_fn): improve docs in server_fn
(#1734)
This commit is contained in:
parent
fafb6c01da
commit
2374439cd8
2 changed files with 15 additions and 8 deletions
|
@ -23,7 +23,7 @@ inventory::collect!(DefaultServerFnTraitObj);
|
|||
|
||||
/// Attempts to find a server function registered at the given path.
|
||||
///
|
||||
/// This can be used by a server to handle the requests, as in the following example (using `actix-web`)
|
||||
/// This can be used by a server to handle the requests, as in the following example (using [`actix-web`]).
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// #[post("{tail:.*}")]
|
||||
|
@ -64,6 +64,8 @@ inventory::collect!(DefaultServerFnTraitObj);
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [`actix-web`]: <https://docs.rs/actix-web/>
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
pub fn server_fn_by_path(
|
||||
path: &str,
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
//!
|
||||
//! ### `#[server]`
|
||||
//!
|
||||
//! The [`#[server]`](https://docs.rs/server_fn/latest/server_fn/attr.server.html) macro allows you to annotate a function to
|
||||
//! The [`#[server]`][server] macro allows you to annotate a function to
|
||||
//! indicate that it should only run on the server (i.e., when you have an `ssr` feature in your
|
||||
//! crate that is enabled).
|
||||
//!
|
||||
|
@ -69,12 +69,15 @@
|
|||
//! - **Server functions must return `Result<T, ServerFnError>`.** Even if the work being done
|
||||
//! inside the function body can’t fail, the processes of serialization/deserialization and the
|
||||
//! network call are fallible.
|
||||
//! - **Return types must implement [Serialize](serde::Serialize).**
|
||||
//! - **Return types must implement [`serde::Serialize`].**
|
||||
//! This should be fairly obvious: we have to serialize arguments to send them to the server, and we
|
||||
//! need to deserialize the result to return it to the client.
|
||||
//! - **Arguments must be implement [serde::Serialize].** They are serialized as an `application/x-www-form-urlencoded`
|
||||
//! form data using [`serde_qs`](https://docs.rs/serde_qs/latest/serde_qs/) or as `application/cbor`
|
||||
//! using [`cbor`](https://docs.rs/cbor/latest/cbor/).
|
||||
//! - **Arguments must be implement [`serde::Serialize`].** They are serialized as an `application/x-www-form-urlencoded`
|
||||
//! form data using [`serde_qs`] or as `application/cbor` using [`cbor`].
|
||||
//!
|
||||
//! [server]: <https://docs.rs/server_fn/latest/server_fn/attr.server.html>
|
||||
//! [`serde_qs`]: <https://docs.rs/serde_qs/latest/serde_qs/>
|
||||
//! [`cbor`]: <https://docs.rs/cbor/latest/cbor/>
|
||||
|
||||
// used by the macro
|
||||
#[doc(hidden)]
|
||||
|
@ -202,7 +205,7 @@ pub enum Payload {
|
|||
|
||||
/// Attempts to find a server function registered at the given path.
|
||||
///
|
||||
/// This can be used by a server to handle the requests, as in the following example (using `actix-web`)
|
||||
/// This can be used by a server to handle the requests, as in the following example (using [`actix-web`])
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// #[post("{tail:.*}")]
|
||||
|
@ -243,6 +246,8 @@ pub enum Payload {
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [`actix-web`]: <https://docs.rs/actix-web/>
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
pub fn server_fn_by_path<T: 'static, R: ServerFunctionRegistry<T>>(
|
||||
path: &str,
|
||||
|
@ -323,7 +328,7 @@ impl quote::ToTokens for Encoding {
|
|||
///
|
||||
/// 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].
|
||||
/// 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.
|
||||
pub trait ServerFn<T: 'static>
|
||||
|
|
Loading…
Reference in a new issue