1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pub use super::defs::*;
pub trait Segment: Sized {
fn remove(&mut self, args: ArgsType);
fn split(&mut self, pos: usize, args: ArgsType) -> Self;
fn modify(&mut self, new_flag: IdentType, args: ArgsType);
fn shrink_to_left(&mut self, pos: usize, args: ArgsType) {
self.split(pos, args).remove(args);
}
fn shrink_to_right(&mut self, pos: usize, args: ArgsType) {
let right = self.split(pos, args);
self.remove(args);
*self = right;
}
fn split_and_remove_middle(
&mut self,
pos_left: usize,
pos_right: usize,
args: ArgsType,
) -> Self {
let right = self.split(pos_right, args);
self.split(pos_left, args).remove(args);
right
}
fn modify_left(&mut self, pos: usize, new_flag: IdentType, args: ArgsType) -> Self {
let right = self.split(pos, args);
self.modify(new_flag, args);
right
}
fn modify_right(&mut self, pos: usize, new_flag: IdentType, args: ArgsType) -> Self {
let mut right = self.split(pos, args);
right.modify(new_flag, args);
right
}
fn modify_middle(
&mut self,
pos_left: usize,
pos_right: usize,
new_flag: IdentType,
args: ArgsType,
) -> (Self, Self) {
let right = self.split(pos_right, args);
let mut middle = self.split(pos_left, args);
middle.modify(new_flag, args);
(middle, right)
}
}