Responses

Struct Responses 

Source
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

Source

pub fn new() -> Responses

Create a new empty responses collection.

Source

pub fn insert( &mut self, path: impl Into<ResponsePath>, value: impl Into<ResponseValue>, )

Insert a response value at the given path.

Source

pub fn get(&self, path: &ResponsePath) -> Option<&ResponseValue>

Get a response value at the given path.

Source

pub fn contains(&self, path: &ResponsePath) -> bool

Check if a response exists at the given path.

Source

pub fn remove(&mut self, path: &ResponsePath) -> Option<ResponseValue>

Remove a response at the given path.

Source

pub fn iter(&self) -> impl Iterator<Item = (&ResponsePath, &ResponseValue)>

Get an iterator over all path-value pairs.

Source

pub fn len(&self) -> usize

Get the number of responses.

Source

pub fn is_empty(&self) -> bool

Check if there are no responses.

Source

pub fn extend(&mut self, other: Responses)

Merge another responses collection into this one.

Source

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());
Source

pub fn get_string(&self, path: &ResponsePath) -> Result<&str, ResponseError>

Get a string value at the given path.

Source

pub fn get_int(&self, path: &ResponsePath) -> Result<i64, ResponseError>

Get an integer value at the given path.

Source

pub fn get_float(&self, path: &ResponsePath) -> Result<f64, ResponseError>

Get a float value at the given path.

Source

pub fn get_bool(&self, path: &ResponsePath) -> Result<bool, ResponseError>

Get a boolean value at the given path.

Source

pub fn get_chosen_variant( &self, path: &ResponsePath, ) -> Result<usize, ResponseError>

Get a chosen variant index at the given path.

Source

pub fn get_chosen_variants( &self, path: &ResponsePath, ) -> Result<&[usize], ResponseError>

Get chosen variant indices at the given path.

Source

pub fn get_string_list( &self, path: &ResponsePath, ) -> Result<&[String], ResponseError>

Get a string list at the given path.

Source

pub fn get_int_list(&self, path: &ResponsePath) -> Result<&[i64], ResponseError>

Get an integer list at the given path.

Source

pub fn get_float_list( &self, path: &ResponsePath, ) -> Result<&[f64], ResponseError>

Get a float list at the given path.

Source

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).

Trait Implementations§

Source§

impl Clone for Responses

Source§

fn clone(&self) -> Responses

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Responses

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Responses

Source§

fn default() -> Responses

Returns the “default value” for a type. Read more
Source§

impl<'a> IntoIterator for &'a Responses

Source§

type Item = (&'a ResponsePath, &'a ResponseValue)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, ResponsePath, ResponseValue>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Responses as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Responses

Source§

type Item = (ResponsePath, ResponseValue)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<ResponsePath, ResponseValue>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <Responses as IntoIterator>::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.