Skip to main content

Grid

Struct Grid 

Source
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: String

The version of this grid

Implementations§

Source§

impl Grid

Source

pub fn make_empty() -> Self

Create an empty Grid

Source

pub fn make_from_dicts(rows: Vec<Dict>) -> Self

Constructs a Grid from a list of Dicts

Source

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")
  }));
Source

pub fn make_err(dis: &str) -> Self

Create an Err Grid

Source

pub fn is_empty(&self) -> bool

True if Grid has no rows

Source

pub fn len(&self) -> usize

Returns number of rows in this Grid

Source

pub fn is_err(&self) -> bool

True if Grid is an error grid

Trait Implementations§

Source§

impl Clone for Grid

Source§

fn clone(&self) -> Grid

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Grid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Grid

Implements the Default trait for the Grid

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Grid

Hayson Grid deserializer

Source§

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.

Source§

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 From<Grid> for Value

Converts from Grid to a Grid Value

Source§

fn from(value: Grid) -> Self

Converts to this type from the input type.
Source§

impl FromBrio for Grid

Source§

fn from_brio<R: Read>(reader: &mut R) -> Result<Self>

Read the complete Brio encoding of Self (ctrl byte + payload) from reader.
Source§

impl Hash for Grid

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<usize> for Grid

Implements the Index trait for the Grid this allows usage such mygrid[1]

Source§

type Output = Dict

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a Grid

Implement IntoIterator for Grid

Source§

type Item = &'a Dict

The type of the elements being iterated over.
Source§

type IntoIter = IterHelper<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> ListFiltered<'a, Dict> for Grid

Source§

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

Source§

fn cmp(&self, other: &Grid) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Grid

Source§

fn eq(&self, other: &Grid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Grid

Source§

fn partial_cmp(&self, other: &Grid) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Grid

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl ToBrio for Grid

Source§

fn to_brio<W: Write>(&self, writer: &mut W) -> Result<()>

Write the Brio encoding of self into writer.
Source§

fn to_brio_vec(&self) -> Result<Vec<u8>>

Convenience: encode to a Vec<u8>.
Source§

impl ToZinc for Grid

Source§

fn to_zinc<W: Write>(&self, writer: &mut W) -> Result<()>

Source§

fn to_zinc_string(&self) -> Result<String>

Encodes this Haystack type as a Zinc string Read more
Source§

impl TryFrom<&Value> for Grid

Tries to convert from Value to a Grid

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Grid

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,