#[non_exhaustive]pub enum Value<'a> {
Absent,
Bool(bool),
Int(i64),
Float(f64),
Text(&'a str),
Html(SafeHtml<'a>),
Display(&'a dyn Display),
View(&'a dyn View),
List(&'a dyn List),
}Expand description
One value read from a view.
use web_net::{SafeHtml, Value, escape_html};
// How an engine writes a value into HTML text.
fn write(v: Value<'_>) -> String {
match v {
Value::Text(t) => escape_html(t).into_owned(),
Value::Html(h) => h.as_str().to_owned(),
Value::Int(i) => i.to_string(),
_ => String::new(),
}
}
assert_eq!(write(Value::Text("a<b")), "a<b");
assert_eq!(write(Value::Html(SafeHtml::trusted("<b>b</b>"))), "<b>b</b>");
assert_eq!(write(Value::Int(3)), "3");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Absent
Nothing here (a missing field, an empty optional).
Bool(bool)
A boolean.
Int(i64)
An integer.
Float(f64)
A float.
Text(&'a str)
Text, escaped for its context by the engine.
Html(SafeHtml<'a>)
Trusted markup, written as it is.
Display(&'a dyn Display)
A computed value (money, a date), written as text and escaped.
View(&'a dyn View)
A nested object.
List(&'a dyn List)
A sequence.
Implementations§
Source§impl Value<'_>
impl Value<'_>
Sourcepub const fn is_absent(&self) -> bool
pub const fn is_absent(&self) -> bool
Whether this is Value::Absent.
use web_net::Value;
assert!(Value::Absent.is_absent());
assert!(!Value::Int(0).is_absent());Sourcepub const fn as_text(&self) -> Option<&str>
pub const fn as_text(&self) -> Option<&str>
The text, for Value::Text.
use web_net::Value;
assert_eq!(Value::Text("hi").as_text(), Some("hi"));
assert_eq!(Value::Int(1).as_text(), None);Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Value<'a>
impl<'a> !Send for Value<'a>
impl<'a> !Sync for Value<'a>
impl<'a> !UnwindSafe for Value<'a>
impl<'a> Forget for Value<'a>
impl<'a> Freeze for Value<'a>
impl<'a> Move for Value<'a>
impl<'a> Unpin for Value<'a>
impl<'a> UnsafeUnpin for Value<'a>
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