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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120



use crate::Object;
use crate::Int;
use crate::Float;
use crate::_String;
use crate::Char;
use crate::Bool;


use super::List;


/// append function for List
/// can append any data type
pub trait Append<T>: Sized {
    /// Performs append
    fn append_back(&mut self, _: T) -> &mut Self;
}


/// inline append for integer
/// example
///
/// let mut one_elem = List::new();
/// one_elem
///     .append_int(123)
///     .append_int(123)
///     .append_int(123)
///     .append_int(123)
///     .append_int(123)
///     .append_int(123)
///     .append_int(123);
/// println!("{}", one_elem);
///
/// [123, 123, 123, 123, 123, 123, 123]
///
impl Append<i32> for List {
    fn append_back(&mut self, _integer: i32) -> &mut Self {
        self._list.push_back(Object::Int(Int::new(_integer)));
        self
    }
}

impl Append<Float<f32>> for List {
    fn append_back(&mut self, _float: Float<f32>) -> &mut Self {
        self._list.push_back(Object::Float32(Float::from(_float)));
        self
    }
}

impl Append<Float<f64>> for List {
    fn append_back(&mut self, _float: Float<f64>) -> &mut Self {
        self._list.push_back(Object::Float64(Float::from(_float)));
        self
    }
}


impl Append<&str> for List {
    fn append_back(&mut self, _static_string: &str) -> &mut Self {
        self._list.push_back(Object::String(_String::from_str(_static_string)));
        self
    }
}


impl Append<char> for List {
    fn append_back(&mut self, _char: char) -> &mut Self {
        self._list.push_back(Object::Char(Char::new(_char)));
        self
    }
}

impl Append<f32> for List {
    fn append_back(&mut self, _float: f32) -> &mut Self {
        self._list.push_back(Object::Float32(Float::from(_float)));
        self
    }
}


impl Append<String> for List {
    fn append_back(&mut self, string: String) -> &mut Self {
        self._list.push_back(Object::String(_String::from_string(string)));
        self
    }
}

impl Append<_String> for List {
    fn append_back(&mut self, _string: _String) -> &mut Self {
        self._list.push_back(Object::String(_string));
        self
    }
}

impl Append<bool> for List {
    fn append_back(&mut self, _bool: bool) ->&mut Self {
        self._list.push_back(Object::Bool(Bool::new(_bool)));
        self
    }
}


impl Append<Bool> for List {

    #[doc = include_str!("../../docs/python_list/append_pbool.md")]
    fn append_back(&mut self, _bool: Bool) ->&mut Self {
        self._list.push_back(Object::Bool(_bool));
        self
    }
}

impl Append<List> for List {
    fn append_back(&mut self, _list: List) -> &mut Self {
        self._list.push_back(Object::List(_list));
        self
    }
}