Skip to main content

cli_core/forms/
loaded.rs

1//! Reads a `load-form` reply back into the form's raw values.
2
3use forms::FormValues;
4
5use crate::transaction::parse_loaded_for;
6use nomiscript::Value;
7
8use crate::render::{RenderError, WireValue, parse_wire};
9
10/// Parse the wire reply of a `load-form` call for `form` into [`FormValues`].
11///
12/// # Errors
13/// The server's refusal message, or a message when the reply is not a payload.
14pub fn parse_loaded_reply(form: &forms::Form, wire: &str) -> Result<FormValues, String> {
15    match parse_wire(wire) {
16        Ok(WireValue::Value(Value::String(text))) => {
17            parse_loaded_for(form, &text).map_err(|e| e.to_string())
18        }
19        Ok(_) => Err("the reply is not a form payload".to_string()),
20        Err(RenderError::Server(reply)) => Err(reply.message),
21        Err(other) => Err(other.to_string()),
22    }
23}
24
25#[cfg(test)]
26mod tests;