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
//! Tuple type for the lexer
//! 
//! This Class Provides a Tuple Type

use std::fmt::Display;
use std::default::Default;
use std::ffi::CString;

#[derive(Clone)]
pub struct Tuple<T1: Default + Display + Clone + Send + Sync, T2: Default + Display + Clone + Send + Sync> {
    pub first: T1,
    pub second: T2,
    pub tuple: (T1, T2),
}

impl<T1: Default + Display + Clone + Send + Sync, T2: Default + Display + Clone + Send + Sync> Default for Tuple<T1, T2> {
    fn default() -> Self {
        Self::new()
    }
}

impl<T1: Default + Display + Clone + Send + Sync, T2: Default + Display + Clone + Send + Sync> Tuple<T1, T2> {

    /// Create a new tuple with default values
    pub fn new() -> Self {
        let first = T1::default();
        let second = T2::default();
        Self {
            first: first.clone(),
            second: second.clone(),
            tuple: (first, second),
        }
    }

    /// Set the first value
    pub fn set_first(&mut self, first: T1) {
        self.first = first.clone();
        self.tuple = (first, self.second.clone());
    }

    /// Set the second value
    pub fn set_second(&mut self, second: T2) {
        self.second = second.clone();
        self.tuple = (self.first.clone(), second);
    }

    pub fn get_first(&self) -> T1 {
        self.first.clone()
    }

    pub fn get_second(&self) -> T2 {
        self.second.clone()
    }

    pub fn first_to_str(&self) -> String {
        self.first.to_string()
    }

    pub fn second_to_str(&self) -> String {
        self.second.to_string()
    }

    pub fn first_to_cstr(&self) -> CString {
        CString::new(self.first.to_string()).unwrap()
    }

    pub fn second_to_cstr(&self) -> CString {
        CString::new(self.second.to_string()).unwrap()
    }

}