o3 0.60.0

shared-nothing primitives
Documentation
pub(in crate::buffer::resident) mod exact;
pub(in crate::buffer::resident) mod state;

use std::ops;

use crate::buffer::{
    self,
    bytes::bounded,
    resident, storage,
    storage::{provided, regions},
};

/// Immutable bytes whose accounting or borrow domain remains in `'d`.
pub type Shared<'d> = regions::Shared<state::State<'d>>;

impl<'d> resident::Budget<'d> {
    pub fn try_copy(
        &self,
        source: &impl bounded::Source,
    ) -> Result<Shared<'d>, resident::copy::Error> {
        Ok(storage::Owned::try_copy(source, self)?.freeze())
    }
}

impl<'d> Shared<'d> {
    pub fn get(&self, range: ops::Range<usize>) -> Option<buffer::View<'_, Self>> {
        buffer::View::new(self).get(range)
    }

    pub fn scope(&self) -> Option<&Self> {
        use resident::Kind;
        match &self.owner().0 {
            Kind::Owned(_) | Kind::Static => None,
            Kind::Slice if self.is_empty() => None,
            Kind::Slice
            | Kind::Resident(_)
            | Kind::Accounted(_)
            | Kind::Provided(_)
            | Kind::Fixed(_) => Some(self),
        }
    }
}

impl<'d, L: provided::Layout>
    From<bounded::Value<storage::Shared<Option<provided::Account<'d, L>>>>> for Shared<'d>
where
    resident::Kind<'d>: From<provided::Account<'d, L>>,
{
    fn from(bytes: bounded::Value<storage::Shared<Option<provided::Account<'d, L>>>>) -> Self {
        bytes.0.into()
    }
}
const _: () = {
    assert!(size_of::<Shared<'static>>() == 4 * size_of::<usize>());
    assert!(size_of::<Option<Shared<'static>>>() == 4 * size_of::<usize>());
};

const _: () = {
    assert!(
        size_of::<crate::buffer::raw::Consumed<'static, Shared<'static>, 8>>()
            == 2 * size_of::<usize>()
    );
    assert!(
        size_of::<Option<crate::buffer::raw::Consumed<'static, Shared<'static>, 8>>>()
            == 2 * size_of::<usize>()
    );
};