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
78
79
80
81
82
83
84
85
use std::ops::Range;

/// RefClone clone a shared reference, equivalent to Clone on e.g. Rc, Arc
pub trait RefClone: Clone {
    /// Clone a shared reference
    fn ref_clone(&self) -> Self;
}
impl<T> RefClone for std::rc::Rc<T> {
    #[inline]
    fn ref_clone(&self) -> Self {
        self.clone()
    }
}
impl<T> RefClone for std::rc::Weak<T> {
    #[inline]
    fn ref_clone(&self) -> Self {
        self.clone()
    }
}
impl<T> RefClone for std::sync::Arc<T> {
    #[inline]
    fn ref_clone(&self) -> Self {
        self.clone()
    }
}
impl<T> RefClone for std::sync::Weak<T> {
    #[inline]
    fn ref_clone(&self) -> Self {
        self.clone()
    }
}

/// Abstraction of a timeline that stores historical records
pub trait TimeTravel: Iterator + RefClone + SyncTo {
    /// Get the value of the specified position  
    /// - None if the timeline is completed but not found  
    /// - None if index is less than 0  
    fn get(&mut self, index: usize) -> Option<Self::Item>;
    /// Check if the timeline is complete
    fn is_complete(&self) -> bool;
    /// Check is ready to next again
    fn re_ready(&mut self);
    /// Re-ready to next
    fn do_ready(&mut self);
    /// Save the current time point
    fn save(&self) -> usize;
    /// Time travel to a point in history
    fn back(&mut self, index: usize);
    /// Calculate the range from save point to current
    fn make_range(&self, from: usize) -> Range<usize> {
        from..self.save()
    }
}

/// Make another instance equal to yourself  
pub trait SyncTo {
    /// let other = self
    fn sync_to(&self, other: &mut Self);
}

/// Calculate String
pub trait ComString {
    type ComStringData;

    /// Calculate String
    fn com_string(&self, data: Self::ComStringData) -> Option<String>;
}
/// Get String
pub trait GetString {
    /// Get String
    fn get_string(&self) -> String;
}

/// Calculate char
pub trait ComChar {
    type ComCharData;

    /// Calculate char
    fn com_char(&self, data: Self::ComCharData) -> Option<char>;
}
/// Get char
pub trait GetChar {
    /// Get char
    fn get_char(&self) -> char;
}