range_action_map/
segment.rs1pub use super::defs::*;
2
3pub trait Segment: Sized {
5 fn remove(&mut self, args: ArgsType);
7 fn split(&mut self, pos: usize, args: ArgsType) -> Self;
11 fn modify(&mut self, new_flag: IdentType, args: ArgsType);
13
14 fn shrink_to_left(&mut self, pos: usize, args: ArgsType) {
18 self.split(pos, args).remove(args);
19 }
20 fn shrink_to_right(&mut self, pos: usize, args: ArgsType) {
24 let right = self.split(pos, args);
25 self.remove(args);
26 *self = right;
27 }
28 fn split_and_remove_middle(
33 &mut self,
34 pos_left: usize,
35 pos_right: usize,
36 args: ArgsType,
37 ) -> Self {
38 let right = self.split(pos_right, args);
39 self.split(pos_left, args).remove(args);
40 right
41 }
42 fn modify_left(&mut self, pos: usize, new_flag: IdentType, args: ArgsType) -> Self {
47 let right = self.split(pos, args);
48 self.modify(new_flag, args);
49 right
50 }
51 fn modify_right(&mut self, pos: usize, new_flag: IdentType, args: ArgsType) -> Self {
56 let mut right = self.split(pos, args);
57 right.modify(new_flag, args);
58 right
59 }
60 fn modify_middle(
66 &mut self,
67 pos_left: usize,
68 pos_right: usize,
69 new_flag: IdentType,
70 args: ArgsType,
71 ) -> (Self, Self) {
72 let right = self.split(pos_right, args);
73 let mut middle = self.split(pos_left, args);
74 middle.modify(new_flag, args);
75 (middle, right)
76 }
77}