use super::super::{dispatch_bindings::*, entities::*, floria_bindings, host};
use std::fmt;
impl CallSite {
pub fn new(id: Id, property: Option<String>) -> Self {
Self { id, property }
}
pub fn entity(&self) -> Result<floria_bindings::Entity, String> {
Ok(host::get_entity(&self.id)?)
}
pub fn property_value(&self) -> Result<Option<Expression>, String> {
Ok(match &self.property {
Some(property) => self.entity()?.property(property).and_then(|property| property.value()),
None => None,
})
}
pub fn property_metadata_string(&self, key: &str) -> Result<Option<String>, String> {
Ok(match &self.property {
Some(property) => self.entity()?.property(property).and_then(|property| property.metadata_string(key)),
None => None,
})
}
}
impl fmt::Display for CallSite {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.id, formatter)?;
if let Some(property) = &self.property {
write!(formatter, ".{}", property)?;
}
Ok(())
}
}