pub enum State {
Text(String),
Json(Value),
}Expand description
The state a crate::Question set is evaluated against.
State is never logged: it may contain PII. See the crate-level docs for the full logging policy.
§Examples
use jev::State;
let from_str: State = "a plain-text ticket body".into();
assert!(matches!(from_str, State::Text(_)));
#[derive(serde::Serialize)]
struct Ticket { subject: String }
let from_struct = State::json(&Ticket { subject: "billing issue".into() }).unwrap();
assert!(matches!(from_struct, State::Json(_)));Variants§
Implementations§
Source§impl State
impl State
Sourcepub fn json<T: Serialize>(value: &T) -> Result<Self, Error>
pub fn json<T: Serialize>(value: &T) -> Result<Self, Error>
Serializes any serde::Serialize value into a JSON State.
This is the common case for domain structs: State::json(&ticket) instead of
hand-building a serde_json::Value.
§Errors
Returns Error::Invalid when value cannot be serialized to JSON.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for State
impl<'de> Deserialize<'de> for State
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for State
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
impl UnwindSafe for State
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more