#![allow(
dead_code,
unused_imports,
unused_variables,
unused_macros,
unused_assignments,
unused_mut,
non_snake_case,
unused_must_use
)]
use std::collections::VecDeque;
use std::fmt;
use std::error;
use std::ops::Add;
use std::ops::Deref;
use std::str::FromStr;
use crate::_Object;
use crate::Object;
use crate::Int;
use crate::Float;
use crate::_String;
use crate::Char;
use crate::Bool;
use crate::type_of;
use crate::print;
use super::Append;
use crate::Iterable;
pub struct List {
pub _list: VecDeque<Object>,
}
impl Iterable for List {
fn __len__(&self) -> usize {
self._list.len()
}
}
impl List {
pub fn new() -> List {
List {
_list: VecDeque::new(),
}
}
fn _contains_char_or_string(&self) -> bool {
for _object in &self._list {
match _object {
Object::String(_object) => {
return true;
},
Object::Char(_object) => {
return true;
},
_ => {},
}
}
false
}
}
impl Default for List {
fn default() -> Self {
Self::new()
}
}
impl _Object for List {
fn __repr__(&self) -> String {
if self._contains_char_or_string() {
format!("\"{}\"", self.__str__())
} else {
format!("'{}'", self.__str__())
}
}
fn __str__(&self) -> String {
if self._list.is_empty() {
return String::from("[]");
}
let mut string_representation = String::new();
let zero = self._list.get(0).unwrap();
match zero {
Object::String(_object) => {
string_representation.push_str(
format!("[{}", _object.__repr__()).as_str(),
);
},
Object::Char(_object) => {
string_representation.push_str(
format!("[{}", _object.__repr__()).as_str(),
);
},
_ => {
string_representation
.push_str(format!("[{}", zero).as_str());
},
};
for _object in self._list.iter().skip(1) {
match _object {
Object::String(_object) => {
string_representation.push_str(
format!(", {}", _object.__repr__()).as_str(),
);
},
Object::Char(_object) => {
string_representation.push_str(
format!(", {}", _object.__repr__()).as_str(),
);
},
_ => {
string_representation
.push_str(format!(", {}", _object).as_str());
},
};
}
string_representation.push(']');
string_representation
}
}
impl fmt::Display for List {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self._list.is_empty() {
write!(f, "[]");
return Ok(());
}
let zero = self._list.get(0).unwrap();
match zero {
Object::String(obj) => write!(f, "[{}", obj.__repr__()),
Object::Char(obj) => write!(f, "[{}", obj.__repr__()),
_ => write!(f, "[{}", zero),
};
for _object in self._list.iter().skip(1) {
match _object {
Object::String(obj) => {
write!(f, ", {}", obj.__repr__())
},
Object::Char(obj) => {
write!(f, ", {}", obj.__repr__())
},
_ => write!(f, ", {}", _object),
};
}
write!(f, "]")
}
}
impl fmt::Debug for List {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self._list.is_empty() {
write!(f, "[]");
return Ok(());
}
let zero = self._list.get(0).unwrap();
match zero {
Object::String(obj) => write!(f, "[{:?}", obj.__repr__()),
Object::Char(obj) => write!(f, "[{:?}", obj.__repr__()),
_ => write!(f, "[{:?}", zero),
};
for _object in self._list.iter().skip(1) {
match _object {
Object::String(obj) => {
write!(f, ", {}", obj.__repr__())
},
Object::Char(obj) => {
write!(f, ", {}", obj.__repr__())
},
_ => write!(f, ", {}", _object),
};
}
write!(f, "]")
}
}
impl Deref for List {
type Target = VecDeque<Object>;
fn deref(&self) -> &Self::Target {
&self._list
}
}
impl From<&str> for List {
fn from(_static_string: &str) -> List {
List {
_list: _static_string
.chars()
.map(|c| Object::Char(Char::from(c)))
.collect(),
}
}
}
impl From<&String> for List {
fn from(_string: &String) -> List {
List {
_list: _string
.chars()
.map(|c| Object::Char(Char::from(c)))
.collect(),
}
}
}
impl From<String> for List {
fn from(_string: String) -> List {
List {
_list: _string
.chars()
.map(|c| Object::Char(Char::from(c)))
.collect(),
}
}
}
impl From<i32> for List {
#[doc = include_str!("../../docs/python_list/showcase.md")]
fn from(_integer: i32) -> List {
let mut vector_deque = VecDeque::new();
vector_deque
.push_back(Object::Int32(Int::<i32>::new(_integer)));
List {
_list: vector_deque,
}
}
}
impl From<&List> for List {
fn from(_list: &List) -> List {
let mut temp_list: VecDeque<Object> = VecDeque::new();
for _object in &_list._list {
}
List {
_list: temp_list
}
}
}
impl FromStr for List {
type Err = Box<dyn error::Error>;
fn from_str(_static_str: &str) -> Result<Self, Self::Err> {
Ok(List::from(_static_str))
}
}
impl FromIterator<i32> for List {
fn from_iter<T: IntoIterator<Item = i32>>(
_integer_iterator: T,
) -> Self {
let mut integer_list = List::new();
for integer in _integer_iterator {
integer_list.append_back(integer);
}
integer_list
}
}
impl FromIterator<String> for List {
fn from_iter<T: IntoIterator<Item = String>>(
_string_iterator: T,
) -> Self {
let mut string_list = List::new();
for _string in _string_iterator {
string_list.append_back(_string);
}
string_list
}
}
impl Add for List {
type Output = List;
fn add(self, rhs: Self) -> Self::Output {
let mut new_list = List::new();
for _object in self._list {
new_list.append_back(_object);
}
for _object in rhs._list {
new_list.append_back(_object);
}
new_list
}
}