python/list/
append.rs

1use crate::Object;
2use crate::Int;
3use crate::Float;
4// use crate::_Object;
5use crate::_String;
6use crate::Char;
7use crate::Bool;
8
9
10use super::List;
11
12
13/// append function for List
14/// can append any data type
15pub trait Append<T>: Sized {
16    /// Performs append
17    fn append_back(&mut self, _: T) -> &mut Self;
18}
19
20
21/// inline append for integer
22/// example
23///
24/// let mut one_elem = List::new();
25/// one_elem
26///     .append_back(123)
27///     .append_back(123)
28///     .append_back(123)
29///     .append_back(123)
30///     .append_back(123)
31///     .append_back(123)
32///     .append_back(123);
33/// println!("{}", one_elem);
34///
35/// [123, 123, 123, 123, 123, 123, 123]
36impl Append<i32> for List {
37    fn append_back(&mut self, _integer: i32) -> &mut Self {
38        self._list.push_back(Object::Int32(Int::new(_integer)));
39        self
40    }
41}
42
43impl Append<i64> for List {
44    fn append_back(&mut self, _integer: i64) -> &mut Self {
45        self._list.push_back(Object::Int64(Int::new(_integer)));
46        self
47    }
48}
49
50
51impl Append<Int<i32>> for List {
52    fn append_back(&mut self, _integer: Int<i32>) -> &mut Self {
53        self._list.push_back(Object::Int32(_integer));
54        self
55    }
56}
57
58impl Append<Int<i64>> for List {
59    fn append_back(&mut self, _integer: Int<i64>) -> &mut Self {
60        self._list.push_back(Object::Int64(_integer));
61        self
62    }
63}
64
65// impl Append<Vec<i32>> for List {
66//     fn append_back(&mut self, _int_vec: Vec<i32>) -> &mut Self {
67//         for _int in _int_vec {
68//             self._list.push_back(Object::Int32(Int::from(_int)));
69//         }
70//         self
71//     }
72// }
73
74
75// impl<T> Append<T> for List
76// where T: Sized {
77//     fn append_back(&mut self, _integer: i32) -> &mut Self {
78//         self._list.push_back(Object::Int32(Int::new(_integer)));
79//         self
80//     }
81// }
82
83
84impl Append<Float<f32>> for List {
85    fn append_back(&mut self, _float: Float<f32>) -> &mut Self {
86        self._list.push_back(Object::Float32(_float));
87        self
88    }
89}
90
91impl Append<Float<f64>> for List {
92    fn append_back(&mut self, _float: Float<f64>) -> &mut Self {
93        self._list.push_back(Object::Float64(_float));
94        self
95    }
96}
97
98impl Append<f64> for List {
99    fn append_back(&mut self, _float: f64) -> &mut Self {
100        self._list.push_back(Object::Float64(Float::new(_float)));
101        self
102    }
103}
104
105
106impl Append<&str> for List {
107    fn append_back(&mut self, _str: &str) -> &mut Self {
108        self._list.push_back(Object::String(_String::from(_str)));
109        self
110    }
111}
112
113
114impl Append<char> for List {
115    fn append_back(&mut self, _char: char) -> &mut Self {
116        self._list.push_back(Object::Char(Char::from(_char)));
117        self
118    }
119}
120
121impl Append<f32> for List {
122    fn append_back(&mut self, _float: f32) -> &mut Self {
123        self._list.push_back(Object::Float32(Float::from(_float)));
124        self
125    }
126}
127
128
129impl Append<String> for List {
130    fn append_back(&mut self, string: String) -> &mut Self {
131        self._list.push_back(Object::String(_String::from(string)));
132        self
133    }
134}
135
136impl Append<_String> for List {
137    fn append_back(&mut self, _string: _String) -> &mut Self {
138        self._list.push_back(Object::String(_string));
139        self
140    }
141}
142
143impl Append<bool> for List {
144    fn append_back(&mut self, _bool: bool) -> &mut Self {
145        self._list.push_back(Object::Bool(Bool::new(_bool)));
146        self
147    }
148}
149
150
151impl Append<Bool> for List {
152    #[doc = include_str!("../../docs/python_list/append_pbool.md")]
153    fn append_back(&mut self, _bool: Bool) -> &mut Self {
154        self._list.push_back(Object::Bool(_bool));
155        self
156    }
157}
158
159impl Append<List> for List {
160    fn append_back(&mut self, _list: List) -> &mut Self {
161        self._list.push_back(Object::List(_list));
162        self
163    }
164}
165
166impl Append<Object> for List {
167    fn append_back(&mut self, object: Object) -> &mut Self {
168        self._list.push_back(object);
169        self
170    }
171}