srdf/srdf_parser/
focus_rdf.rs1use crate::{Query, RDFParseError};
2
3pub trait FocusRDF: Query {
7 fn set_focus(&mut self, focus: &Self::Term);
9
10 fn get_focus(&self) -> &Option<Self::Term>;
12
13 fn get_focus_as_term(&self) -> Result<&Self::Term, RDFParseError> {
15 match self.get_focus() {
16 None => Err(RDFParseError::NoFocusNode),
17 Some(term) => Ok(term),
18 }
19 }
20
21 fn get_focus_as_subject(&self) -> Result<Self::Subject, RDFParseError> {
23 match self.get_focus() {
24 None => Err(RDFParseError::NoFocusNode),
25 Some(term) => {
26 let subject =
27 term.clone()
28 .try_into()
29 .map_err(|_| RDFParseError::ExpectedSubject {
30 node: format!("{term}"),
31 })?;
32 Ok(subject)
33 }
34 }
35 }
36}