ft_sdk/
form.rs

1pub type Result = std::result::Result<ft_sdk::chr::CHR<Output>, ft_sdk::Error>;
2
3#[derive(Debug)]
4pub enum Output {
5    Redirect(String),
6    Reload,
7}
8
9impl From<ft_sdk::chr::CHR<Output>>
10    for std::result::Result<http::Response<bytes::Bytes>, ft_sdk::Error>
11{
12    fn from(
13        ft_sdk::chr::CHR {
14            cookies,
15            headers,
16            response,
17        }: ft_sdk::chr::CHR<Output>,
18    ) -> Self {
19        let response = match response {
20            Output::Redirect(url) => crate::json(serde_json::json!({"redirect": url })),
21            Output::Reload => crate::json(serde_json::json!({"reload": true })),
22        }?;
23        ft_sdk::chr::chr(cookies, headers, response)
24    }
25}
26
27pub fn redirect<S: AsRef<str>>(url: S) -> Result {
28    Ok(ft_sdk::chr::CHR::new(Output::Redirect(
29        url.as_ref().to_string(),
30    )))
31}
32
33pub fn reload() -> Result {
34    Ok(ft_sdk::chr::CHR::new(Output::Reload))
35}