astreams: Add conversion traits

This commit is contained in:
Steffo 2025-02-14 06:53:33 +01:00
parent 41b6c6be7b
commit 7c16904dc3
Signed by: steffo
GPG key ID: 6B8E18743E7E1F86

View file

@ -58,8 +58,6 @@ pub trait HasLinkedDataInterface: Sized {
fn ld_set_children(&mut self, id: &str, values: Vec<Self>) -> ResultSetMany;
}
pub type ResultConvert<W> = Option<W>;
pub trait IsLinkedDataWrapper
where
Self: Sized,
@ -77,10 +75,40 @@ where
fn into_ref(self) -> &'b B;
fn try_into_read_wrapper<Other>(self) -> ResultConvert<Other>
fn from_read_unchecked<Other>(other: Other) -> Self
where Other: IsLinkedDataReadWrapper<'b, B>
{
Other::from_ref_checked(self.into_ref())
Self::from_ref_unchecked(other.into_ref())
}
fn from_read_checked<Other>(other: Other) -> Option<Self>
where Other: IsLinkedDataReadWrapper<'b, B>
{
Self::from_ref_checked(other.into_ref())
}
fn from_write_unchecked<Other>(other: Other) -> Self
where Other: IsLinkedDataWriteWrapper<'b, B>
{
Self::from_ref_unchecked(other.into_mut())
}
fn from_write_checked<Other>(other: Other) -> Option<Self>
where Other: IsLinkedDataWriteWrapper<'b, B>
{
Self::from_ref_checked(other.into_mut())
}
fn into_read_unchecked<Other>(self) -> Other
where Other: IsLinkedDataReadWrapper<'b, B>
{
Other::from_read_unchecked(self)
}
fn into_read_checked<Other>(self) -> Option<Other>
where Other: IsLinkedDataReadWrapper<'b, B>
{
Other::from_read_checked(self)
}
}
@ -95,15 +123,51 @@ where
fn into_mut(self) -> &'b mut B;
fn try_into_write_wrapper<Other>(self) -> ResultConvert<Other>
fn from_write_unchecked<Other>(other: Other) -> Self
where Other: IsLinkedDataWriteWrapper<'b, B>
{
Other::from_mut_checked(self.into_mut())
Self::from_mut_unchecked(other.into_mut())
}
fn try_into_read_wrapper<Other>(self) -> ResultConvert<Other>
fn from_write_create<Other>(other: Other) -> Self
where Other: IsLinkedDataWriteWrapper<'b, B>
{
Self::from_mut_create(other.into_mut())
}
fn from_write_checked<Other>(other: Other) -> Option<Self>
where Other: IsLinkedDataWriteWrapper<'b, B>
{
Self::from_mut_checked(other.into_mut())
}
fn into_read_unchecked<Other>(self) -> Other
where Other: IsLinkedDataReadWrapper<'b, B>
{
Other::from_ref_checked(self.into_mut())
Other::from_write_unchecked(self)
}
fn into_read_checked<Other>(self) -> Option<Other>
where Other: IsLinkedDataReadWrapper<'b, B>
{
Other::from_write_checked(self)
}
fn into_write_unchecked<Other>(self) -> Other
where Other: IsLinkedDataWriteWrapper<'b, B>
{
Other::from_write_unchecked(self)
}
fn into_write_create<Other>(self) -> Other
where Other: IsLinkedDataWriteWrapper<'b, B>
{
Other::from_write_create(self)
}
fn into_write_checked<Other>(self) -> Option<Other>
where Other: IsLinkedDataWriteWrapper<'b, B>
{
Other::from_write_checked(self)
}
}