Lines
85.71 %
Functions
75 %
Branches
100 %
//! Reads a `load-form` reply back into the form's raw values.
use forms::FormValues;
use crate::transaction::parse_loaded_for;
use nomiscript::Value;
use crate::render::{RenderError, WireValue, parse_wire};
/// Parse the wire reply of a `load-form` call for `form` into [`FormValues`].
///
/// # Errors
/// The server's refusal message, or a message when the reply is not a payload.
pub fn parse_loaded_reply(form: &forms::Form, wire: &str) -> Result<FormValues, String> {
match parse_wire(wire) {
Ok(WireValue::Value(Value::String(text))) => {
parse_loaded_for(form, &text).map_err(|e| e.to_string())
}
Ok(_) => Err("the reply is not a form payload".to_string()),
Err(RenderError::Server(reply)) => Err(reply.message),
Err(other) => Err(other.to_string()),
#[cfg(test)]
mod tests;