1 use anyhow::Result; 2 use format_buf::format; 3 4 use std::any::Any; 5 6 use build_info_common::CrateInfo; 7 8 use super::{as_arguments_0, as_field_name, FormatSpecifier, Type, Value, OP_FIELD_ACCESS}; 9 10 impl Value for CrateInfo { call(&self, func: &str, args: &[Box<dyn Value>]) -> Result<Box<dyn Value>>11 fn call(&self, func: &str, args: &[Box<dyn Value>]) -> Result<Box<dyn Value>> { 12 match func { 13 OP_FIELD_ACCESS => match as_field_name(args) { 14 "name" => Ok(Box::new(self.name.clone())), 15 "version" => Ok(Box::new(self.version.clone())), 16 "authors" => Ok(Box::new(self.authors.clone())), 17 "license" => Ok(Box::new(self.license.clone())), 18 "enabled_features" => Ok(Box::new(self.enabled_features.clone())), 19 "available_features" => Ok(Box::new(self.available_features.clone())), 20 "dependencies" => Ok(Box::new(self.dependencies.clone())), 21 _ => self.call_base(func, args), 22 }, 23 "to_string" => { 24 as_arguments_0(args)?; 25 Ok(Box::new(self.to_string())) 26 } 27 _ => self.call_base(func, args), 28 } 29 } 30 get_type(&self) -> Type31 fn get_type(&self) -> Type { 32 Type::CrateInfo 33 } 34 as_any(&self) -> &dyn Any35 fn as_any(&self) -> &dyn Any { 36 self 37 } 38 format(&self, buffer: &mut String, spec: FormatSpecifier)39 fn format(&self, buffer: &mut String, spec: FormatSpecifier) { 40 match spec { 41 FormatSpecifier::Default => format!(buffer, "{}", self), 42 FormatSpecifier::Debug => format!(buffer, "{:?}", self), 43 FormatSpecifier::DebugAlt => format!(buffer, "{:#?}", self), 44 } 45 } 46 } 47