dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Fix/server macro defaults

Open Nathy-bajo opened this issue 1 year ago • 1 comments

Enhanced the #[server] macro documentation for improved clarity and usability. Key updates:

  • Expanded explanations of arguments with examples (e.g., prefix, input, output).
  • Showcased advanced features like middleware layers and context sharing.
  • Refactored the macro implementation to replace hardcoded default values for better readability and maintainability.
  • Enhanced error handling with detailed messages to help developers debug issues effectively.

Nathy-bajo avatar Dec 19 '24 12:12 Nathy-bajo

Thanks for working on this! It looks like some unrelated changes to base path leaked into this PR.

The two main fields that need documentation are the input and output fields. Since they effect both the encoding and the trait bounds on the inputs and outputs, it would be useful to include examples with the full server function, instead of just the encoding type. Here are a few examples of the bounds they imply:

/// Setting the type to `StreamingJson` means you need to return something that implements From<JsonStream<T>>
/// where T implements serde::serialize and serde::de::DeserializeOwned
#[server(output = StreamingJson)]
pub async fn json_stream_fn() -> Result<JsonStream<String>, ServerFnError> {
    todo!()
}

/// Setting the type to `StreamingText` means you need to return something that implements From<TextStream>
#[server(output = StreamingText)]
pub async fn text_stream_fn() -> Result<TextStream, ServerFnError> {
    todo!()
}

/// Setting the type to `PostUrl` means you need to return something that implements Serialize and Deserialize.
/// This uses `serde_qs` which imposes the following requirements:
/// - Be less than 5 levels deep
/// - Contain no `serde(flatten)` attributes
#[server(output = PostUrl)]
pub async fn form_fn() -> Result<TextStream, ServerFnError> {
    todo!()
}

ealmloff avatar Dec 20 '24 14:12 ealmloff

Thanks for working on this! It looks like some unrelated changes to base path leaked into this PR.

The two main fields that need documentation are the input and output fields. Since they effect both the encoding and the trait bounds on the inputs and outputs, it would be useful to include examples with the full server function, instead of just the encoding type. Here are a few examples of the bounds they imply:

/// Setting the type to `StreamingJson` means you need to return something that implements From<JsonStream<T>>
/// where T implements serde::serialize and serde::de::DeserializeOwned
#[server(output = StreamingJson)]
pub async fn json_stream_fn() -> Result<JsonStream<String>, ServerFnError> {
    todo!()
}

/// Setting the type to `StreamingText` means you need to return something that implements From<TextStream>
#[server(output = StreamingText)]
pub async fn text_stream_fn() -> Result<TextStream, ServerFnError> {
    todo!()
}

/// Setting the type to `PostUrl` means you need to return something that implements Serialize and Deserialize.
/// This uses `serde_qs` which imposes the following requirements:
/// - Be less than 5 levels deep
/// - Contain no `serde(flatten)` attributes
#[server(output = PostUrl)]
pub async fn form_fn() -> Result<TextStream, ServerFnError> {
    todo!()
}

I have added the examples as requested @ealmloff 😄

Nathy-bajo avatar Dec 23 '24 11:12 Nathy-bajo