MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / from

Method from

aiscript-vm/src/lib.rs:160–205  ·  view source on GitHub ↗
(value: Value<'gc>)

Source from the content-addressed store, hash-verified

158
159impl<'gc> From<Value<'gc>> for ReturnValue {
160 fn from(value: Value<'gc>) -> Self {
161 match value {
162 Value::Number(value) => ReturnValue::Number(value),
163 Value::Boolean(value) => ReturnValue::Boolean(value),
164 Value::String(value) => ReturnValue::String(value.to_string()),
165 Value::IoString(value) => ReturnValue::String(value.to_string()),
166 Value::List(value) => ReturnValue::Array(
167 value
168 .borrow()
169 .data
170 .iter()
171 .map(|item| item.to_serde_value())
172 .collect::<Vec<_>>(),
173 ),
174 Value::Instance(instance) => {
175 if instance.borrow().class.borrow().name.to_str().unwrap() == "Response" {
176 return ReturnValue::Response(
177 instance
178 .borrow()
179 .fields
180 .iter()
181 .map(|(key, value)| (key.to_string(), value.to_serde_value()))
182 .collect(),
183 );
184 } else {
185 ReturnValue::Object(
186 instance
187 .borrow()
188 .fields
189 .iter()
190 .map(|(key, value)| (key.to_string(), value.to_serde_value()))
191 .collect(),
192 )
193 }
194 }
195 Value::Object(obj) => ReturnValue::Object(
196 obj.borrow()
197 .fields
198 .iter()
199 .map(|(key, value)| (key.to_string(), value.to_serde_value()))
200 .collect(),
201 ),
202 Value::Agent(agent) => ReturnValue::Agent(agent.name.to_string()),
203 _ => ReturnValue::Nil,
204 }
205 }
206}
207
208pub fn eval(source: &'static str) -> Result<ReturnValue, VmError> {

Callers

nothing calls this directly

Calls 6

ResponseClass · 0.85
ObjectClass · 0.85
AgentClass · 0.85
to_serde_valueMethod · 0.80
to_strMethod · 0.80
borrowMethod · 0.45

Tested by

no test coverage detected