pub struct ConsolidateMrsP<T, R, S>where
R: GetBeginEnd<T>,
S: RangeBounds<T>,{ /* private fields */ }Expand description
This struct acts as an owned wrapper for the Option::Some produced by the Consolidate Iterator, which then acts as a normal instance of GetBeginEnd.
Implementations§
Source§impl<T, R, S> ConsolidateMrsP<T, R, S>where
R: GetBeginEnd<T>,
S: RangeBounds<T>,
impl<T, R, S> ConsolidateMrsP<T, R, S>where
R: GetBeginEnd<T>,
S: RangeBounds<T>,
Sourcepub fn new(src: (R, Vec<(usize, S)>)) -> Self
pub fn new(src: (R, Vec<(usize, S)>)) -> Self
Wwraps the data set and makes it operate as if it is the instance src.0.
Sourcepub fn as_src(self) -> (R, Vec<(usize, S)>)
pub fn as_src(self) -> (R, Vec<(usize, S)>)
Converts back to the orignal data set used to create this instance.
Examples found in repository?
examples/overlaps.rs (line 21)
3fn main() {
4 for result in Consolidate::num_defaults(
5 [
6 1..=4,
7 3..=5,
8 10..=12,
9 10..=11,
10 13..=13,
11 // This will produce an error, because 13..=13 is "After" 1..=2.
12 1..=2,
13 ]
14 .into_iter(),
15 )
16 .to_consolidate_checker(ConsolidationOrder::Forward)
17 {
18 match result {
19 Ok(row) => {
20 // get our outer range and src rows.
21 let (outer, src) = row.as_src();
22 println!("Outer Range: {}->{}", outer.start(), outer.end());
23 for (id, original) in src {
24 println!(
25 " Row: {}, Range: {}->{}",
26 id,
27 original.start(),
28 original.end()
29 );
30 }
31 }
32 Err((msg, row)) => {
33 let (outer, src) = row.as_src();
34 println!(
35 "Error: {}, \n Produced range: {}->{}",
36 msg,
37 outer.start(),
38 outer.end()
39 );
40 for (id, original) in src {
41 println!(
42 " Caused by: Row: {}, Range: {}->{}",
43 id,
44 original.start(),
45 original.end()
46 );
47 }
48 }
49 }
50 }
51}Sourcepub fn src(&self) -> &Vec<(usize, S)>
pub fn src(&self) -> &Vec<(usize, S)>
Returns a ref to the internal data set.
Examples found in repository?
examples/columns.rs (line 90)
3fn main() {
4 // We create all of our column data unsorted
5 let mut col_a = vec![0..=11, 2..=3, 7..=9, 22..=33, 34..=39];
6 let mut col_b = vec![6..=9, 6..=9, 6..=7, 11..=22, 7..=11, 9..=9];
7 let mut col_c = vec![3..=4, 3..=9, 4..=6, 30..=41];
8
9 // ** Full Sort Example here! **
10 // We will use this to drive the internals of the sort function
11 let t = NumberIncDecCpCmp::defaults();
12
13 // We create our sort function here
14 let sort_by = |a: &std::ops::RangeInclusive<i32>, b: &std::ops::RangeInclusive<i32>| {
15 sort_forward(a, b, &t.default_rebound(), &t)
16 };
17
18 // Sort all of our rows and force them to exist in the correct order!
19 col_a.sort_by(sort_by);
20 col_b.sort_by(sort_by);
21 col_c.sort_by(sort_by);
22 // ** End Full Sort Example **
23
24 // Create our Columns instance using number defaults.
25 let cols = Columns::num_defaults();
26
27 // give up if we fail to add a column!
28 assert!(cols.add_column(col_a.into_iter()).is_ok());
29 assert!(cols.add_column(col_b.into_iter()).is_ok());
30 assert!(cols.add_column(col_c.into_iter()).is_ok());
31
32 // Just pretty printing our text table border
33 println!(
34 "+---------+-----------+{:-<35}+{:-<61}+{:-<35}+",
35 "", "", ""
36 );
37
38 // Pretty preint our text table header
39 println!(
40 "| Overlap | State(id) |{:^35}|{:^61}|{:^35}|",
41 "Column(A)", "Column(B)", "Column(C)"
42 );
43
44 // In order to access the iter.get_column(column_id) method, the iter instance must remain in scope.
45 // If access to the causal ranges is not required, then a standard for lopp iterator will work.
46 let mut iter = cols.into_iter();
47 let mut id = 0;
48 loop {
49 let next = iter.next();
50 if next.is_none() {
51 // print out the last text bumper.
52 println!(
53 "+---------+-----------+{:-<35}+{:-<61}+{:-<35}+",
54 "", "", ""
55 );
56 return;
57 }
58 let (overlap, res, columns) = next.unwrap();
59 // print a bumper text row.
60 println!(
61 "+---------+-----------+{:-<35}+{:-<61}+{:-<35}+",
62 "", "", ""
63 );
64
65 // Print out the common intersecting range!
66 print!("| {:^2}->{:^2} |", overlap.get_begin(), overlap.get_end());
67 let mut stop = false;
68 if res.is_err() {
69 print!(" Err({}) |", id);
70 // We still want to access the column or columns that error out before we stop
71 stop = true;
72 } else {
73 print!(" Ok({}) |", id);
74 }
75 for (column_id, col) in columns.iter().enumerate() {
76 let mut txt = Vec::new();
77 match col {
78 Ok(src) => {
79 for row in src {
80 // This range contains all of the ranges that were used to create it!
81 let container = row.as_ref();
82 txt.push(format!(
83 "[{}->{}](",
84 container.get_begin(),
85 container.get_end()
86 ));
87 let mut r = Vec::new();
88
89 // walk our raw source ranges that caused this larger range
90 for (row_id, range) in container.src().iter() {
91 r.push(format!("{}({}->{})", row_id, range.start(), range.end()));
92 }
93 txt.push(r.join(","));
94 txt.push(String::from(")"));
95 }
96 }
97 Err(msg) => {
98 // This code exists but does not execute in this example.
99 // The Err code block, exists to demonstrate how to gain access to the ranges that
100 // caused a given error.
101
102 // Save our error for output
103 txt.push(String::from(*msg));
104
105 // get our raw column and the original rows that caused the error!
106 let col = iter.get_column(column_id).unwrap();
107
108 // This Vec contains the rows that caused the error!
109 let rows = col.get_rows();
110 for row in rows {
111 let result_range = row.as_ref();
112 // The range that was generated from the raw ranges
113 txt.push(format!(
114 "Invalid Range: ({}->{})",
115 result_range.get_begin(),
116 result_range.get_end()
117 ));
118 for (row_id, range) in result_range.src().iter() {
119 // One ore more of these ranges caused the error!
120 txt.push(format!("({}){}->{}", row_id, range.start(), range.end()))
121 }
122 }
123 }
124 }
125 match column_id {
126 0 => print!("{:^35}|", txt.join("")),
127 1 => print!("{:^61}|", txt.join("")),
128 2 => print!("{:^35}|", txt.join("")),
129 _ => (),
130 }
131 }
132
133 println!();
134 if stop {
135 // stop here if we ran into an error processing an iterator.
136 break;
137 }
138 id += 1;
139 }
140}Trait Implementations§
Source§impl<T, R: GetBeginEnd<T>, S: RangeBounds<T>> GetBeginEnd<T> for ConsolidateMrsP<T, R, S>
impl<T, R: GetBeginEnd<T>, S: RangeBounds<T>> GetBeginEnd<T> for ConsolidateMrsP<T, R, S>
Source§impl<T, R: GetBeginEnd<T>, S: RangeBounds<T>> RangeBounds<T> for ConsolidateMrsP<T, R, S>
impl<T, R: GetBeginEnd<T>, S: RangeBounds<T>> RangeBounds<T> for ConsolidateMrsP<T, R, S>
Source§fn start_bound(&self) -> Bound<&T>
fn start_bound(&self) -> Bound<&T>
Wraps the return value from self.get_begin() in a std::ops::Bound::Included.
Source§fn end_bound(&self) -> Bound<&T>
fn end_bound(&self) -> Bound<&T>
Wraps the return value from self.get_end() in a std::ops::Bound::Included.
Auto Trait Implementations§
impl<T, R, S> Freeze for ConsolidateMrsP<T, R, S>where
R: Freeze,
impl<T, R, S> RefUnwindSafe for ConsolidateMrsP<T, R, S>
impl<T, R, S> Send for ConsolidateMrsP<T, R, S>
impl<T, R, S> Sync for ConsolidateMrsP<T, R, S>
impl<T, R, S> Unpin for ConsolidateMrsP<T, R, S>
impl<T, R, S> UnsafeUnpin for ConsolidateMrsP<T, R, S>where
R: UnsafeUnpin,
impl<T, R, S> UnwindSafe for ConsolidateMrsP<T, R, S>
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