use crate::{entities::AnonymousIndividual, fmt::DisplayPretty, literals::Literal};
use rdftk_iri::{Iri, Name};
use strum::{EnumIs, EnumTryAs};
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, string::String, vec::Vec};
#[derive(Clone, Debug, PartialEq)]
pub struct Annotation {
property: Iri,
value: AnnotationValue,
annotations: Vec<Annotation>, }
#[derive(Clone, Debug, PartialEq, EnumIs, EnumTryAs)]
pub enum AnnotationValue {
Iri(Iri),
Literal(Literal),
AnonymousIndividual(AnonymousIndividual),
}
pub trait HasAnnotations {
fn has_annotations(&self) -> bool;
fn annotations(&self) -> Box<dyn Iterator<Item = &Annotation> + '_>;
fn annotations_mut(&mut self) -> Box<dyn Iterator<Item = &mut Annotation> + '_>;
}
impl_display_pretty!(Annotation(property, value, @list annotations));
impl_has_annotations!(Annotation);
impl Annotation {
pub fn new(property: Iri, value: AnnotationValue) -> Self {
Self::new_with_annotations(property, value, Vec::default())
}
pub fn new_with_annotations<I>(property: Iri, value: AnnotationValue, annotations: I) -> Self
where
I: IntoIterator<Item = Annotation>,
{
Self {
property,
value,
annotations: annotations.into_iter().collect(),
}
}
pub fn property(&self) -> &Iri {
&self.property
}
pub fn value(&self) -> &AnnotationValue {
&self.value
}
}
impl_display_pretty!(AnnotationValue enum Iri, Literal, AnonymousIndividual);
impl_from_for_variant!(AnnotationValue, Iri);
impl_from_for_variant!(AnnotationValue, Literal);
impl_from_for_variant!(AnnotationValue, Literal(from String));
impl_from_for_variant!(AnnotationValue, AnonymousIndividual);
impl_from_for_variant!(AnnotationValue, AnonymousIndividual(from Name));