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
use crate::vm::value::Value; use crate::vm::value::Undefined; use crate::vm::value::Null; use crate::vm::value::Number; use crate::vm::value::String; use crate::vm::value::Symbol; use crate::vm::value::Object; use std::fmt; use std::string; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] pub struct Boolean(pub bool); impl fmt::Display for Boolean { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.0 { true => write!(f, "true"), false => write!(f, "false"), } } } impl From<bool> for Boolean { fn from(val: bool) -> Self { Boolean(val) } } impl Into<bool> for Boolean { fn into(self) -> bool { self.0 } } impl From<Undefined> for Boolean { fn from(val: Undefined) -> Self { Boolean(false) } } impl From<Null> for Boolean { fn from(val: Null) -> Self { Boolean(false) } } impl From<String> for Boolean { fn from(val: String) -> Self { Boolean(val.0.len() != 0) } } impl<'a> From<&'a String> for Boolean { fn from(val: &'a String) -> Self { Boolean(val.0.len() != 0) } } impl From<Number> for Boolean { fn from(val: Number) -> Self { Boolean(val.into()) } } impl From<Object> for Boolean { fn from(val: Object) -> Self { Boolean(true) } } impl<'a> From<&'a Object> for Boolean { fn from(val: &'a Object) -> Self { Boolean(true) } } impl From<Symbol> for Boolean { fn from(val: Symbol) -> Self { Boolean(true) } } impl From<&Symbol> for Boolean { fn from(val: &Symbol) -> Self { Boolean(true) } }