Unnamed repository; edit this file 'description' to name the repository.
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
|
use std::ops::{Deref, DerefMut};
use serde::{Deserialize, Serialize};
#[derive(Clone, Serialize, Deserialize, Default, Debug)]
pub struct Bookmark {
pub position: usize,
pub text: String,
}
#[derive(Clone, Serialize, Deserialize, Default, Debug)]
pub struct Bookmarks(Vec<Bookmark>);
impl DerefMut for Bookmarks {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl Deref for Bookmarks {
type Target = Vec<Bookmark>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Bookmarks {
pub fn manipulate(&mut self, mut f: impl FnMut(usize) -> usize) {
for lem in &mut self.0 {
lem.position = f(lem.position);
}
}
}
|