use super::super::{
NativeAttributeExpressionFailure, NativeAttributeOperandError, observe_expression_value,
};
use super::{NativeAttributeHead, NativeAttributeModelExpression};
use crate::dialect::vue3::operand::model_parts;
pub struct NativeModelHead<'h, 'o, 'a> {
head: &'h NativeAttributeHead<'o, 'a>,
}
impl<'o, 'a> NativeAttributeHead<'o, 'a> {
pub fn model(
&self,
) -> Result<Option<NativeModelHead<'_, 'o, 'a>>, NativeAttributeOperandError> {
Ok(model_parts(self.directive(), self.name_block())?
.then_some(NativeModelHead { head: self }))
}
}
impl<'h, 'o, 'a> NativeModelHead<'h, 'o, 'a> {
#[must_use]
pub fn head(&self) -> &'h NativeAttributeHead<'o, 'a> {
self.head
}
pub fn observe_expression(
self,
) -> Result<NativeAttributeModelExpression<'a>, NativeAttributeExpressionFailure<'a>> {
let (origin, syntax) =
observe_expression_value(self.head.selected(), self.head.attribute().reborrow())?;
Ok(NativeAttributeModelExpression { origin, syntax })
}
}