(
&self,
start: &Option<Box<dyn Value>>,
end: &Option<Box<dyn Value>>,
)
| 99 | } |
| 100 | |
| 101 | fn slice_op( |
| 102 | &self, |
| 103 | start: &Option<Box<dyn Value>>, |
| 104 | end: &Option<Box<dyn Value>>, |
| 105 | ) -> Result<Box<dyn Value>, String> { |
| 106 | if start.is_none() && end.is_none() { |
| 107 | return Ok(Box::new(self.clone())); |
| 108 | } |
| 109 | |
| 110 | let mut start_index: usize = 0; |
| 111 | |
| 112 | if start.is_some() { |
| 113 | if let Some(start_value) = start.clone().unwrap().as_any().downcast_ref::<IntValue>() { |
| 114 | if start_value.value < 1 || start_value.value >= self.values.len() as i64 { |
| 115 | return Err("Slice start must be between 1 and length of Array".to_string()); |
| 116 | } |
| 117 | start_index = start_value.value as usize; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | let mut end_index: usize = self.values.len(); |
| 122 | if end.is_some() { |
| 123 | if let Some(end_value) = end.clone().unwrap().as_any().downcast_ref::<IntValue>() { |
| 124 | if end_value.value < start_index as i64 |
| 125 | || end_value.value > self.values.len() as i64 |
| 126 | { |
| 127 | return Err("Slice end must be between start and length of Array".to_string()); |
| 128 | } |
| 129 | end_index = end_value.value as usize; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | let slice = self.values[start_index..end_index].to_vec(); |
| 134 | Ok(Box::new(ArrayValue { |
| 135 | values: slice, |
| 136 | base_type: self.base_type.clone(), |
| 137 | })) |
| 138 | } |
| 139 | |
| 140 | fn logical_or_op(&self, other: &Box<dyn Value>) -> Result<Box<dyn Value>, String> { |
| 141 | if let Some(other_array) = other.as_any().downcast_ref::<ArrayValue>() { |
no test coverage detected