pub enum Content {
Text(String),
Object(Map<String, Value>),
Array(Vec<Value>),
}Expand description
Text or structured JSON: what the API reference writes as string | object | array, and
TypeSafe’s own SDKs call JSONContent.
Instructions, the descriptions of a Choice’s options, a
Score’s levels and a Noul’s two outcomes all take it. Text
is the common case, and a &str or String converts with into(). Structure is for a
question that refers to data of its own: put the data in one field and the question in
another, and name the data field in backticks.
use serde_json::json;
use typesafe_jev::Content;
let text: Content = "Is the resume for the same person?".into();
assert_eq!(text.as_str(), Some("Is the resume for the same person?"));
let structured = Content::try_from(json!({
"potential_duplicate": {"name": "John Smith", "location": "Oakland, California"},
"question": "Is the resume for the same person as `potential_duplicate`?",
}))?;
assert!(matches!(structured, Content::Object(_)));
// A number, a boolean or null is not content.
assert!(Content::try_from(json!(42)).is_err());Variants§
Text(String)
Plain text.
Object(Map<String, Value>)
A JSON object, whose fields the text of a question can name in backticks.
Array(Vec<Value>)
A JSON array.
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Content
impl<'de> Deserialize<'de> for Content
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 Content
Auto Trait Implementations§
impl Freeze for Content
impl RefUnwindSafe for Content
impl Send for Content
impl Sync for Content
impl Unpin for Content
impl UnsafeUnpin for Content
impl UnwindSafe for Content
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