Struct takoyaki::PrintableGrid
source · pub struct PrintableGrid {
pub grid: Vec<Vec<Printable>>,
}
Expand description
Handles printing the data to the terminal
Fields§
§grid: Vec<Vec<Printable>>
The raw grid
Implementations§
source§impl PrintableGrid
impl PrintableGrid
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of the printable
Example:
use takoyaki::PrintableGrid;
let printable = Printable::new()
sourcepub fn pluck(data: &Value, dest: &str) -> Value
pub fn pluck(data: &Value, dest: &str) -> Value
Iterates over the raw data and find the data at the specific destionation
Arguments
data
- The raw data that needs to be looped throughdest
- A string that includes all the key path to the destination separated by dots.
Example:
use takoyaki::PrintableGrid;
use serde_json::json;
let data = json!({
"children": {
"are_human_dumb": true
}
});
assert_eq!(PrintableGrid::pluck(&data, "children.are_human_dumb"), json!(true))
sourcepub fn insert_at(&mut self, x: usize, y: usize, item: Printable)
pub fn insert_at(&mut self, x: usize, y: usize, item: Printable)
Inserts a item
at x
and y
positions in a 2d grid
Arguments
x
: The position on the x asisy
: The position on the y asisitem
: The item that needs to be inserted
Example
use takoyaki::{PrintableGrid,Printable};
let mut grid = PrintableGrid::new();
let printable = Printable { color: "".to_string(), count: 0 };
grid.insert_at(2, 2, printable.clone());
assert_eq!(grid.grid[2][2], printable);
sourcepub fn generate_grid(&mut self, opts: PrintOptions<'_>, data: Value)
pub fn generate_grid(&mut self, opts: PrintOptions<'_>, data: Value)
Generates the grid according the the print option
sourcepub fn pretty_print(&self) -> Result<()>
pub fn pretty_print(&self) -> Result<()>
Pretty prints the grid