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
use anyhow::Result;
use format_buf::format;
use std::any::Any;
use build_info_common::CrateInfo;
use super::{as_arguments_0, as_field_name, FormatSpecifier, Type, Value, OP_FIELD_ACCESS};
impl Value for CrateInfo {
fn call(&self, func: &str, args: &[Box<dyn Value>]) -> Result<Box<dyn Value>> {
match func {
OP_FIELD_ACCESS => match as_field_name(args) {
"name" => Ok(Box::new(self.name.clone())),
"version" => Ok(Box::new(self.version.clone())),
"authors" => Ok(Box::new(self.authors.clone())),
"license" => Ok(Box::new(self.license.clone())),
"enabled_features" => Ok(Box::new(self.enabled_features.clone())),
"available_features" => Ok(Box::new(self.available_features.clone())),
"dependencies" => Ok(Box::new(self.dependencies.clone())),
_ => self.call_base(func, args),
},
"to_string" => {
as_arguments_0(args)?;
Ok(Box::new(self.to_string()))
}
_ => self.call_base(func, args),
}
}
fn get_type(&self) -> Type {
Type::CrateInfo
}
fn as_any(&self) -> &dyn Any {
self
}
fn format(&self, buffer: &mut String, spec: FormatSpecifier) {
match spec {
FormatSpecifier::Default => format!(buffer, "{}", self),
FormatSpecifier::Debug => format!(buffer, "{:?}", self),
FormatSpecifier::DebugAlt => format!(buffer, "{:#?}", self),
}
}
}