MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / slice_op

Method slice_op

crates/gitql-core/src/values/array.rs:101–138  ·  view source on GitHub ↗
(
        &self,
        start: &Option<Box<dyn Value>>,
        end: &Option<Box<dyn Value>>,
    )

Source from the content-addressed store, hash-verified

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>() {

Callers 1

Calls 2

as_anyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected