pub struct Responses { /* private fields */ }Expand description
Collected responses from a survey.
Uses ResponsePath as keys to support hierarchical field access.
Response paths are flat (not nested) - a nested field like address.street
is stored with the key ResponsePath::from("address.street").
Implementations§
Source§impl Responses
impl Responses
Sourcepub fn insert(
&mut self,
path: impl Into<ResponsePath>,
value: impl Into<ResponseValue>,
)
pub fn insert( &mut self, path: impl Into<ResponsePath>, value: impl Into<ResponseValue>, )
Insert a response value at the given path.
Sourcepub fn get(&self, path: &ResponsePath) -> Option<&ResponseValue>
pub fn get(&self, path: &ResponsePath) -> Option<&ResponseValue>
Get a response value at the given path.
Sourcepub fn contains(&self, path: &ResponsePath) -> bool
pub fn contains(&self, path: &ResponsePath) -> bool
Check if a response exists at the given path.
Sourcepub fn remove(&mut self, path: &ResponsePath) -> Option<ResponseValue>
pub fn remove(&mut self, path: &ResponsePath) -> Option<ResponseValue>
Remove a response at the given path.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&ResponsePath, &ResponseValue)>
pub fn iter(&self) -> impl Iterator<Item = (&ResponsePath, &ResponseValue)>
Get an iterator over all path-value pairs.
Sourcepub fn filter_prefix(&self, prefix: &ResponsePath) -> Responses
pub fn filter_prefix(&self, prefix: &ResponsePath) -> Responses
Filter responses to only those with the given path prefix, removing the prefix from keys.
This is used when reconstructing nested types - extract responses for a nested
struct and strip the prefix so the nested from_responses sees root-level paths.
§Example
use elicitor_types::{Responses, ResponsePath, ResponseValue};
let mut responses = Responses::new();
responses.insert("address.street", "123 Main St");
responses.insert("address.city", "Springfield");
responses.insert("name", "Alice");
let address_responses = responses.filter_prefix(&ResponsePath::new("address"));
assert!(address_responses.get(&ResponsePath::new("street")).is_some());
assert!(address_responses.get(&ResponsePath::new("city")).is_some());
assert!(address_responses.get(&ResponsePath::new("name")).is_none());Sourcepub fn get_string(&self, path: &ResponsePath) -> Result<&str, ResponseError>
pub fn get_string(&self, path: &ResponsePath) -> Result<&str, ResponseError>
Get a string value at the given path.
Sourcepub fn get_int(&self, path: &ResponsePath) -> Result<i64, ResponseError>
pub fn get_int(&self, path: &ResponsePath) -> Result<i64, ResponseError>
Get an integer value at the given path.
Sourcepub fn get_float(&self, path: &ResponsePath) -> Result<f64, ResponseError>
pub fn get_float(&self, path: &ResponsePath) -> Result<f64, ResponseError>
Get a float value at the given path.
Sourcepub fn get_bool(&self, path: &ResponsePath) -> Result<bool, ResponseError>
pub fn get_bool(&self, path: &ResponsePath) -> Result<bool, ResponseError>
Get a boolean value at the given path.
Sourcepub fn get_chosen_variant(
&self,
path: &ResponsePath,
) -> Result<usize, ResponseError>
pub fn get_chosen_variant( &self, path: &ResponsePath, ) -> Result<usize, ResponseError>
Get a chosen variant index at the given path.
Sourcepub fn get_chosen_variants(
&self,
path: &ResponsePath,
) -> Result<&[usize], ResponseError>
pub fn get_chosen_variants( &self, path: &ResponsePath, ) -> Result<&[usize], ResponseError>
Get chosen variant indices at the given path.
Sourcepub fn get_string_list(
&self,
path: &ResponsePath,
) -> Result<&[String], ResponseError>
pub fn get_string_list( &self, path: &ResponsePath, ) -> Result<&[String], ResponseError>
Get a string list at the given path.
Sourcepub fn get_int_list(&self, path: &ResponsePath) -> Result<&[i64], ResponseError>
pub fn get_int_list(&self, path: &ResponsePath) -> Result<&[i64], ResponseError>
Get an integer list at the given path.
Sourcepub fn get_float_list(
&self,
path: &ResponsePath,
) -> Result<&[f64], ResponseError>
pub fn get_float_list( &self, path: &ResponsePath, ) -> Result<&[f64], ResponseError>
Get a float list at the given path.
Sourcepub fn has_value(&self, path: &ResponsePath) -> bool
pub fn has_value(&self, path: &ResponsePath) -> bool
Check if a response at the given path has a non-empty value.
This is used for Option<T> fields: returns false if the response
is missing OR if it’s an empty string (user skipped the optional field).