use crate::lazy::encoder::annotation_seq::AnnotationSeq;
use crate::lazy::encoder::value_writer::{AnnotatableWriter, ValueWriter};
use crate::lazy::encoder::write_as_ion::WriteAsIon;
use crate::IonResult;
pub struct Annotated<'a, T: ?Sized, A: 'a> {
value: &'a T,
annotations: A,
}
pub trait Annotatable {
#[cfg_attr(not(feature = "experimental-reader-writer"), allow(dead_code))]
fn annotated_with<'a, A: 'a>(&'a self, annotations: A) -> Annotated<'a, Self, A>
where
&'a A: AnnotationSeq<'a>;
}
impl<T> Annotatable for T
where
T: ?Sized + WriteAsIon,
{
fn annotated_with<'a, A: 'a>(&'a self, annotations: A) -> Annotated<'a, Self, A>
where
&'a A: AnnotationSeq<'a>,
{
Annotated {
value: self,
annotations,
}
}
}
impl<'annotations, T, A: 'annotations> WriteAsIon for Annotated<'annotations, T, A>
where
for<'x> &'x A: AnnotationSeq<'x>,
T: WriteAsIon,
{
fn write_as_ion<V: ValueWriter>(&self, writer: V) -> IonResult<()> {
let value_writer = <V as AnnotatableWriter>::with_annotations(writer, &self.annotations)?;
self.value.write_as_ion(value_writer)
}
}