MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / get_variable

Method get_variable

cel/src/context.rs:145–181  ·  view source on GitHub ↗
(&'a self, name: S)

Source from the content-addressed store, hash-verified

143 }
144
145 pub fn get_variable<S>(&'a self, name: S) -> Option<Cow<'a, dyn Val>>
146 where
147 S: AsRef<str>,
148 {
149 let name = name.as_ref();
150 match self {
151 Context::Child {
152 variables,
153 parent,
154 resolver,
155 } => resolver
156 .and_then(|r| {
157 r.resolve(name)
158 .map(|v| Cow::<dyn Val>::Owned(v.try_into().unwrap()))
159 })
160 .or_else(|| {
161 variables
162 .get(name)
163 .map(|b| Cow::<dyn Val>::Borrowed(b.as_ref()))
164 .or_else(|| parent.get_variable(name))
165 }),
166 Context::Root {
167 variables,
168 resolver,
169 ..
170 } => resolver
171 .and_then(|r| {
172 r.resolve(name)
173 .map(|v| Cow::<dyn Val>::Owned(v.try_into().unwrap()))
174 })
175 .or_else(|| {
176 variables
177 .get(name)
178 .map(|v| Cow::<dyn Val>::Borrowed(v.as_ref()))
179 }),
180 }
181 }
182
183 pub(crate) fn env(&self) -> &Env {
184 match self {

Callers 1

resolve_valMethod · 0.80

Calls 4

mapMethod · 0.80
try_intoMethod · 0.80
resolveMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected