matchmaker/preview/
mod.rs1pub mod previewer;
2mod view;
3pub use view::Preview;
4
5use std::ops::Deref;
7use std::sync::{Arc, RwLock};
8
9#[derive(Debug, Clone)]
10pub struct AppendOnly<T>(Arc<RwLock<boxcar::Vec<T>>>);
11
12impl<T> Default for AppendOnly<T> {
13 fn default() -> Self {
14 Self::new()
15 }
16}
17
18impl<T> AppendOnly<T> {
19 pub fn new() -> Self {
20 Self(Arc::new(RwLock::new(boxcar::Vec::new())))
21 }
22
23 pub fn is_empty(&self) -> bool {
24 let guard = self.0.read().unwrap();
25 guard.is_empty()
26 }
27
28 pub fn len(&self) -> usize {
29 let guard = self.0.read().unwrap();
30 guard.count()
31 }
32
33 pub fn clear(&self) {
34 let mut guard = self.0.write().unwrap(); guard.clear();
36 }
37
38 pub fn push(&self, val: T) {
39 let guard = self.0.read().unwrap();
40 guard.push(val);
41 }
42
43 pub fn map_to_vec<U, F>(&self, mut f: F) -> Vec<U>
44 where
45 F: FnMut(&T) -> U,
46 {
47 let guard = self.0.read().unwrap();
48 guard.iter().map(move |(_i, v)| f(v)).collect()
49 }
50}
51
52impl<T> Deref for AppendOnly<T> {
53 type Target = RwLock<boxcar::Vec<T>>;
54
55 fn deref(&self) -> &Self::Target {
56 &self.0
57 }
58}