python/list/
extend.rs

1use crate::{
2    _Object,
3    Append,
4    Int,
5};
6
7/// extend the current list with anything
8pub trait Extend<T>: Sized + _Object {
9    #[doc = include_str!("../../docs/python_list/methods/extend.md")]
10    fn extend(&mut self, _: T) -> &mut Self;
11}
12
13
14use super::List;
15
16
17impl Extend<List> for List {
18    fn extend(&mut self, _container: List) -> &mut Self {
19        for _object in _container._list {
20            self.append_back(_object);
21        }
22        self
23    }
24}
25
26impl Extend<&str> for List {
27    fn extend(&mut self, _str: &str) -> &mut Self {
28        for _char in _str.chars() {
29            self.append_back(_char);
30        }
31        self
32    }
33}
34
35impl Extend<String> for List {
36    fn extend(&mut self, _string: String) -> &mut Self {
37        for _char in _string.chars() {
38            self.append_back(_char);
39        }
40        self
41    }
42}
43
44
45impl<T> Extend<Vec<T>> for List
46where
47    T: Sized,
48    List: Append<T>,
49{
50    fn extend(&mut self, _vec: Vec<T>) -> &mut Self {
51        for _item in _vec {
52            self.append_back(_item);
53        }
54        self
55    }
56}
57
58
59impl Extend<i32> for List {
60    fn extend(&mut self, _int: i32) -> &mut Self {
61        self.append_back(_int);
62        self
63    }
64}
65
66
67impl Extend<Int<i32>> for List {
68    fn extend(&mut self, _int: Int<i32>) -> &mut Self {
69        self.append_back(_int);
70        self
71    }
72}
73
74
75// too hard
76// impl<T> Extend<&[T]> for List
77// where T: Sized, List: Append<T>
78// {
79//     fn extend(&mut self, _vec: &[T]) -> &mut Self {
80//         for _item in _vec {
81//             self.append_back(_item);
82//         }
83//         self
84//     }
85// }