use crate::private::layout::{PointerBuilder, PointerReader};
use crate::Result;
#[derive(Copy, Clone)]
pub struct Owned(());
impl crate::traits::Owned for Owned {
type Reader<'a> = Reader<'a>;
type Builder<'a> = Builder<'a>;
}
impl crate::introspect::Introspect for Owned {
fn introspect() -> crate::introspect::Type {
crate::introspect::TypeVariant::Data.into()
}
}
pub type Reader<'a> = &'a [u8];
pub(crate) unsafe fn reader_from_raw_parts<'a>(p: *const u8, len: u32) -> Reader<'a> {
::core::slice::from_raw_parts(p, len as usize)
}
impl<'a> crate::traits::FromPointerReader<'a> for Reader<'a> {
fn get_from_pointer(
reader: &PointerReader<'a>,
default: Option<&'a [crate::Word]>,
) -> Result<Reader<'a>> {
reader.get_data(default)
}
}
pub type Builder<'a> = &'a mut [u8];
pub(crate) unsafe fn builder_from_raw_parts<'a>(p: *mut u8, len: u32) -> Builder<'a> {
::core::slice::from_raw_parts_mut(p, len as usize)
}
impl<'a> crate::traits::FromPointerBuilder<'a> for Builder<'a> {
fn init_pointer(builder: PointerBuilder<'a>, size: u32) -> Builder<'a> {
builder.init_data(size)
}
fn get_from_pointer(
builder: PointerBuilder<'a>,
default: Option<&'a [crate::Word]>,
) -> Result<Builder<'a>> {
builder.get_data(default)
}
}
impl<'a> crate::traits::SetterInput<Owned> for Reader<'a> {
fn set_pointer_builder<'b>(
mut pointer: PointerBuilder<'b>,
value: Reader<'a>,
_canonicalize: bool,
) -> Result<()> {
pointer.set_data(value);
Ok(())
}
}
impl<'a> From<Reader<'a>> for crate::dynamic_value::Reader<'a> {
fn from(d: Reader<'a>) -> crate::dynamic_value::Reader<'a> {
crate::dynamic_value::Reader::Data(d)
}
}
impl<'a> From<Builder<'a>> for crate::dynamic_value::Builder<'a> {
fn from(d: Builder<'a>) -> crate::dynamic_value::Builder<'a> {
crate::dynamic_value::Builder::Data(d)
}
}