use crate::ty;
use crate::{BodyBuf, Signature, Storable};
use super::{StoreArray, StoreStruct};
#[must_use = "Writers must be used to store the contents of the variant"]
pub struct StoreVariant<'a> {
buf: &'a mut BodyBuf,
}
impl<'a> StoreVariant<'a> {
pub(crate) fn new(buf: &'a mut BodyBuf, signature: &Signature) -> Self {
buf.write_only(signature);
Self { buf }
}
#[inline]
pub fn store<T>(self, value: T)
where
T: Storable,
{
value.store_to(self.buf);
}
#[inline]
pub fn store_array<E>(self) -> StoreArray<'a, E>
where
E: ty::Aligned,
{
StoreArray::new(self.buf)
}
#[inline]
pub fn store_struct<F>(self) -> StoreStruct<'a, F>
where
F: ty::Fields,
{
StoreStruct::new(self.buf)
}
}