pub trait List {
// Required methods
fn len(&self) -> usize;
fn get(&self, index: usize) -> Value<'_>;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
A sequence a template can loop over.
use web_net::{List, Value};
struct Tags<'a>(&'a [&'a str]);
impl List for Tags<'_> {
fn len(&self) -> usize { self.0.len() }
fn get(&self, index: usize) -> Value<'_> {
self.0.get(index).map_or(Value::Absent, |t| Value::Text(t))
}
}
let tags = Tags(&["rust", "web"]);
assert_eq!(tags.get(1).as_text(), Some("web"));
assert!(tags.get(2).is_absent());
assert!(!tags.is_empty());Required Methods§
Sourcefn get(&self, index: usize) -> Value<'_>
fn get(&self, index: usize) -> Value<'_>
An item, or Value::Absent past the end.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".