pub struct Grid {
pub meta: Option<Dict>,
pub columns: Vec<Column>,
pub rows: Vec<Dict>,
pub ver: String,
}Expand description
Haystack Grid
§Example
Create Grid from list of Dicts
use libhaystack::dict;
use libhaystack::val::*;
let rows = vec![
dict! {
"site" => Value::make_marker(),
"dis" => Value::make_str("Site")
},
dict! {
"equip" => Value::make_marker(),
"navName" => Value::make_str("Equip")
},
];
let grid = Grid::make_from_dicts(rows);
assert_eq!(grid.is_empty(), false);
// Get the first row from `Grid`
assert_eq!(grid[0], dict! {
"site" => Value::make_marker(),
"dis" => Value::make_str("Site")
});Fields§
§meta: Option<Dict>Optional Grid meta-data dictionary
columns: Vec<Column>List of the columns this Grid has
rows: Vec<Dict>List of the row for this Grid
ver: StringThe version of this grid
Implementations§
Source§impl Grid
impl Grid
Sourcepub fn make_empty() -> Self
pub fn make_empty() -> Self
Create an empty Grid
Sourcepub fn make_from_dicts(rows: Vec<Dict>) -> Self
pub fn make_from_dicts(rows: Vec<Dict>) -> Self
Constructs a Grid from a list of Dicts
Sourcepub fn make_from_dicts_with_meta(rows: Vec<Dict>, meta: Dict) -> Self
pub fn make_from_dicts_with_meta(rows: Vec<Dict>, meta: Dict) -> Self
Constructs a Grid from a list of Dicts with a meta Dict
§Example
Create Grid from list of Dicts with metadata
use libhaystack::dict;
use libhaystack::val::*;
let rows = vec![
dict! {
"site" => Value::make_marker(),
"dis" => Value::make_str("Site")
},
dict! {
"equip" => Value::make_marker(),
"navName" => Value::make_str("Equip")
},
];
let grid = Grid::make_from_dicts_with_meta(rows, dict! {
"dis" => Value::make_str("A Test Grid")
});
assert_eq!(grid.is_empty(), false);
assert_eq!(grid.meta, Some(dict! {
"dis" => Value::make_str("A Test Grid")
}));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Grid
Hayson Grid deserializer
impl<'de> Deserialize<'de> for Grid
Hayson Grid deserializer
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Grid, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Grid, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a> Filtered<'a, Option<&'a Dict>> for Grid
Implement the Filtered trait for Grid.
impl<'a> Filtered<'a, Option<&'a Dict>> for Grid
Implement the Filtered trait for Grid.
Source§fn filter(&'a self, filter: &Filter) -> Option<&'a Dict>
fn filter(&'a self, filter: &Filter) -> Option<&'a Dict>
This will find the first matching Dict in the grid, one None
§Example
use libhaystack::dict;
use libhaystack::val::{Dict, Grid, Value};
use libhaystack::filter::{Filter, Filtered};
let rows = vec![
dict! {
"site" => Value::make_marker(),
"dis" => Value::make_str("Site")
},
dict! {
"equip" => Value::make_marker(),
"navName" => Value::make_str("Equip")
},
];
let grid = Grid::make_from_dicts(rows);
assert_eq!(grid.filter(&Filter::try_from("equip and navName").expect("Filter")), Some(&dict! {
"equip" => Value::make_marker(),
"navName" => Value::make_str("Equip")
}));Source§impl Index<usize> for Grid
Implements the Index trait for the Grid
this allows usage such mygrid[1]
impl Index<usize> for Grid
Implements the Index trait for the Grid
this allows usage such mygrid[1]
Source§impl<'a> IntoIterator for &'a Grid
Implement IntoIterator for Grid
impl<'a> IntoIterator for &'a Grid
Implement IntoIterator for Grid
Source§impl<'a> ListFiltered<'a, Dict> for Grid
impl<'a> ListFiltered<'a, Dict> for Grid
Source§fn filter_all(&'a self, filter: &Filter) -> Vec<&'a Dict>
fn filter_all(&'a self, filter: &Filter) -> Vec<&'a Dict>
Find all rows in the grid that match the given filter.
§Example
use libhaystack::dict;
use libhaystack::val::{Dict, Grid, Value};
use libhaystack::filter::{Filter, ListFiltered};
let rows = vec![
dict! { "a" => Value::make_marker()},
dict! { "b" => Value::make_marker()}];
let grid = Grid::make_from_dicts(rows);
let res = grid.filter_all(&Filter::try_from("a or b").unwrap());
assert_eq!(res.len(), 2);Source§impl Ord for Grid
impl Ord for Grid
Source§impl PartialOrd for Grid
impl PartialOrd for Grid
impl Eq for Grid
impl StructuralPartialEq for Grid
Auto Trait Implementations§
impl Freeze for Grid
impl RefUnwindSafe for Grid
impl Send for Grid
impl Sync for Grid
impl Unpin for Grid
impl UnsafeUnpin for Grid
impl UnwindSafe for Grid
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