[][src]Struct calcify::Tree

pub struct Tree { /* fields omitted */ }

Tree of Collections for saving to a file.

Methods

impl Tree[src]

pub fn new(name: &'static str) -> Tree[src]

Returns new Tree

Name is the only required metadata.

Arguments

  • name - string

Example

use calcify::Tree;
use calcify::Collection;
use calcify::Bin;
use calcify::ThreeVec;

let f_col: Collection<f64> = Collection::from_vec(vec![0.0,0.0]);
let mut v3_col: Collection<ThreeVec> = Collection::empty();
for _i in 0..9999 {v3_col.push(ThreeVec::random(1.0));}
let col_hist: Collection<Bin> = v3_col.map(ThreeVec::r).hist(50);
let mut ttree = Tree::new("Test_Tree");
ttree.add_field("Desc", "This is a Tree for testing.");
ttree.add_branch("fcol", f_col, "f64");
ttree.add_branch("col_3v", v3_col, "ThreeVec");
ttree.add_branch("hist_3v", col_hist, "Bin");

pub fn add_field(&mut self, key: &'static str, f: &'static str)[src]

pub fn add_branch<T: 'static + Serializable>(
    &mut self,
    key: &'static str,
    b: Collection<T>,
    t: &'static str
)
[src]

Inserts new branch into Tree.

Arguments

  • key - Hash key, &'static str
  • b - Branch, Collection<T: Serializable>
  • t - Collection subtype, &'static str, one of "f64", "String", "ThreeVec", "ThreeMat", "FourVec", "FourMat"

Panics

  • t is invalid

pub fn get_branch(&mut self, key: &'static str) -> Option<&Branch>[src]

Returns Branch from a Trees

Note

  • Branch has no internal Collection functionality, this is intended to only be used with the appropriate extract function to get the Collection.

Arguments

key - &'static str

Example

use calcify::Tree;
use calcify::Collection;
use calcify::Bin;

let f_col: Collection<f64> = Collection::from_vec(vec![0.0,0.0]);
let s_col: Collection<String> = Collection::from_vec(vec![String::from("test0"),String::from("test1")]);
let b_col: Collection<Bin> = Collection::from_vec(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]);
let mut ttree = Tree::new("Test_Tree");
ttree.add_branch("fcol", f_col, "f64");
ttree.add_branch("sCol", s_col, "String");
ttree.add_branch("bCol", b_col, "Bin");

let ex_f_col: Collection<f64> = ttree.get_branch("fcol").unwrap().extract_f64().unwrap();
let ex_s_col: Collection<String> = ttree.get_branch("sCol").unwrap().extract_str();
let ex_b_col: Collection<Bin> = ttree.get_branch("bCol").unwrap().extract_bin().unwrap();

assert_eq!(Collection::from_vec(vec![0.0,0.0]),ex_f_col);
assert_eq!(Collection::from_vec(vec![String::from("test0"),String::from("test1")]),ex_s_col);
assert_eq!(Collection::from_vec(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]),ex_b_col);

Trait Implementations

Auto Trait Implementations

impl !Send for Tree

impl !Sync for Tree

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.