use super::super::{super::path::*, annotations::*, maybe::*, r#struct::*};
use kutil::std::immutable::*;
pub trait Annotated
where
Self: Sized,
{
fn can_have_annotations() -> bool;
fn annotations(&self) -> Option<&Annotations>;
fn annotations_mut(&mut self) -> Option<&mut Annotations>;
fn has_annotations(&self) -> bool {
if Self::can_have_annotations()
&& let Some(annotations) = self.annotations()
{
annotations.has_some()
} else {
false
}
}
fn maybe_annotations(&self) -> MaybeAnnotations<Self> {
MaybeAnnotations::new_from(self)
}
fn with_annotations(mut self, annotations: Annotations) -> Self {
if Self::can_have_annotations()
&& let Some(self_annotations) = self.annotations_mut()
{
*self_annotations = annotations;
}
self
}
fn with_annotations_option(mut self, annotations: Option<Annotations>) -> Self {
if Self::can_have_annotations()
&& let Some(annotations) = annotations
&& let Some(self_annotations) = self.annotations_mut()
{
*self_annotations = annotations;
}
self
}
fn with_annotations_from<AnnotatedT>(mut self, source: &AnnotatedT) -> Self
where
AnnotatedT: Annotated,
{
if Self::can_have_annotations()
&& let Some(annotations) = source.annotations()
&& let Some(self_annotations) = self.annotations_mut()
{
*self_annotations = annotations.clone();
}
self
}
fn with_annotations_from_field<AnnotatedFieldsT>(mut self, source: &AnnotatedFieldsT, name: &str) -> Self
where
AnnotatedFieldsT: AnnotatedStruct,
{
if Self::can_have_annotations() {
if let Some(annotations) = source.field_or_struct_annotations(name)
&& let Some(self_annotations) = self.annotations_mut()
{
*self_annotations = annotations.clone();
}
}
self
}
fn with_source(mut self, source: &Option<ByteString>) -> Self {
if Self::can_have_annotations()
&& let Some(annotations) = self.annotations_mut()
{
annotations.source = source.clone();
}
self
}
fn with_path(mut self, path: Option<PathRepresentation>) -> Self {
if Self::can_have_annotations()
&& let Some(annotations) = self.annotations_mut()
{
annotations.path = path;
}
self
}
fn with_path_list_index(mut self, index: usize) -> Self {
if Self::can_have_annotations()
&& let Some(annotations) = self.annotations_mut()
&& let Some(path) = &mut annotations.path
{
path.push_list_index(index);
}
self
}
fn with_path_map_key(mut self, key: ByteString) -> Self {
if Self::can_have_annotations()
&& let Some(annotations) = self.annotations_mut()
&& let Some(path) = &mut annotations.path
{
path.push_map_key(key);
}
self
}
fn with_span(mut self, span: Option<Span>) -> Self {
if Self::can_have_annotations()
&& let Some(annotations) = self.annotations_mut()
{
annotations.span = span;
}
self
}
fn with_label(mut self, label: Option<Label>) -> Self {
if Self::can_have_annotations()
&& let Some(annotations) = self.annotations_mut()
{
annotations.label = label;
}
self
}
}