use core::marker::PhantomData;
use crate::{
Field,
type_lists::{
ConsSet,
GetPtr,
SculptPtr,
TupleSet,
},
};
pub struct LensMut<'a, T>
where
T: TupleSet,
{
storage: T::ConsPtr,
_phantom: PhantomData<&'a ()>,
}
impl<'a, T> LensMut<'a, T>
where
T: TupleSet,
{
#[inline]
pub(crate) const fn new(storage: T::ConsPtr) -> Self {
Self {
storage,
_phantom: PhantomData,
}
}
#[expect(clippy::type_complexity, reason = "help")]
#[inline]
pub fn split<Lhs, Indices>(
self,
) -> (
LensMut<'a, Lhs>,
LensMut<
'a,
<<T::ConsPtr as SculptPtr<Lhs::ConsPtr, Indices>>::Remainder as ConsSet>::Tuple,
>,
)
where
Lhs: TupleSet,
T::ConsPtr: SculptPtr<Lhs::ConsPtr, Indices>,
<T::ConsPtr as SculptPtr<Lhs::ConsPtr, Indices>>::Remainder: ConsSet<
Tuple: TupleSet<ConsPtr = <T::ConsPtr as SculptPtr<Lhs::ConsPtr, Indices>>::Remainder>,
>,
{
let (lhs_storage, rem_storage) = self.storage.sculpt_ptr();
(
LensMut {
storage: lhs_storage,
_phantom: PhantomData,
},
LensMut {
storage: rem_storage,
_phantom: PhantomData,
},
)
}
#[inline]
pub fn as_ptr<Elt, Index>(&self) -> *const Elt::Type
where
Elt: Field + 'static,
T::ConsPtr: GetPtr<Elt, Index>,
{
self.storage.get_ptr().as_ptr()
}
#[inline]
pub fn as_mut_ptr<Elt, Index>(&mut self) -> *mut Elt::Type
where
Elt: Field + 'static,
T::ConsPtr: GetPtr<Elt, Index>,
{
self.storage.get_ptr().as_ptr()
}
#[expect(
clippy::should_implement_trait,
reason = "signature is generic over the field type, not interchangeable with `AsRef`"
)]
#[inline]
#[must_use]
pub fn as_ref<Elt, Index>(&self) -> &Elt::Type
where
Elt: Field + 'static,
T::ConsPtr: GetPtr<Elt, Index>,
{
unsafe { &*self.storage.get_ptr().as_ptr() }
}
#[expect(
clippy::should_implement_trait,
reason = "signature is generic over the field type, not interchangeable with `AsMut`"
)]
#[inline]
#[must_use]
pub fn as_mut<Elt, Index>(&mut self) -> &mut Elt::Type
where
Elt: Field + 'static,
T::ConsPtr: GetPtr<Elt, Index>,
{
unsafe { &mut *self.storage.get_ptr().as_ptr() }
}
}