Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_text/src/access.rs

1.2 KiB, 7 runs

created by r1870400018:1093, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use crate::{
2 lines::TextLines,
3};
4
5use oxedyne_fe2o3_core::prelude::*;
6
7use std::{
8 fmt,
9 marker::{
10 Sync,
11 },
12 rc::Rc,
13 sync::{
14 Arc,
15 RwLock,
16 RwLockWriteGuard,
17 },
18};
19
20
21#[derive(Clone, Debug)]
22pub enum AccessibleText<
23 T: Clone + fmt::Debug + Default + Sync,
24 D: Clone + fmt::Debug + Default + Sync,
25> {
26 ThreadShared(Arc<RwLock<TextLines<T, D>>>),
27 Shared(Rc<RwLock<TextLines<T, D>>>),
28}
29
30impl<
31 T: Clone + fmt::Debug + Default + Sync,
32 D: Clone + fmt::Debug + Default + Sync,
33>
34 Default for AccessibleText<T, D>
35{
36 fn default() -> Self {
37 Self::Shared(Rc::new(RwLock::new(TextLines::default())))
38 }
39}
40
41impl<
42 T: Clone + fmt::Debug + Default + Sync,
43 D: Clone + fmt::Debug + Default + Sync,
44>
45 AccessibleText<T, D>
46{
47 pub fn get_text_lines(&self) -> Outcome<RwLockWriteGuard<'_, TextLines<T, D>>> {
48 match self {
49 AccessibleText::ThreadShared(locked) => Ok(lock_write!(locked)),
50 AccessibleText::Shared(locked) => Ok(lock_write!(locked)),
51 }
52 }
53
54 pub fn get_text_lines_mut(&mut self) -> Outcome<RwLockWriteGuard<'_, TextLines<T, D>>> {
55 self.get_text_lines()
56 }
57}