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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
use std::any::Any; use object::Object; pub struct VMError { inner: Box<Object> } impl<T> From<T> for VMError where T: Object + 'static { fn from(other: T) -> VMError { VMError { inner: Box::new(other) } } } impl<'a> From<&'a str> for VMError { fn from(other: &'a str) -> VMError { VMError { inner: Box::new(other.to_string()) } } } impl VMError { pub fn unwrap(self) -> Box<Object> { self.inner } } pub struct ValidateError { description: String } impl Object for ValidateError { fn get_children(&self) -> Vec<usize> { Vec::new() } fn as_any(&self) -> &Any { self as &Any } fn as_any_mut(&mut self) -> &mut Any { self as &mut Any } fn to_str(&self) -> &str { self.description.as_str() } } impl ValidateError { pub fn new<T: ToString>(desc: T) -> ValidateError { ValidateError { description: desc.to_string() } } } pub struct ParseError { description: String } impl Object for ParseError { fn get_children(&self) -> Vec<usize> { Vec::new() } fn as_any(&self) -> &Any { self as &Any } fn as_any_mut(&mut self) -> &mut Any { self as &mut Any } fn to_str(&self) -> &str { self.description.as_str() } } impl ParseError { pub fn new<T: ToString>(desc: T) -> ParseError { ParseError { description: desc.to_string() } } } pub struct RuntimeError { description: String } impl Object for RuntimeError { fn get_children(&self) -> Vec<usize> { Vec::new() } fn as_any(&self) -> &Any { self as &Any } fn as_any_mut(&mut self) -> &mut Any { self as &mut Any } fn to_str(&self) -> &str { self.description.as_str() } } impl RuntimeError { pub fn new<T: ToString>(desc: T) -> RuntimeError { RuntimeError { description: desc.to_string() } } } pub struct FieldNotFoundError { field_name: String } impl Object for FieldNotFoundError { fn get_children(&self) -> Vec<usize> { Vec::new() } fn as_any(&self) -> &Any { self as &Any } fn as_any_mut(&mut self) -> &mut Any { self as &mut Any } fn to_string(&self) -> String { format!("Field not found: {}", self.field_name) } } impl FieldNotFoundError { pub fn from_field_name<T: ToString>(name: T) -> FieldNotFoundError { FieldNotFoundError { field_name: name.to_string() } } }