Skip to main content

luaur_analysis/methods/
txn_log_get_mutable.rs

1//! @interface-stub
2use crate::functions::get_mutable_txn_log::get_mutable_pending_type;
3use crate::functions::get_mutable_txn_log_alt_c::get_mutable_pending_type_pack;
4use crate::functions::get_mutable_type::get_mutable_type_id;
5use crate::functions::get_mutable_type_pack::get_mutable_type_pack_id;
6use crate::records::txn_log::TxnLog;
7use crate::type_aliases::type_id::TypeId;
8use crate::type_aliases::type_pack_id::TypePackId;
9use crate::type_aliases::type_pack_variant::TypePackVariantMember;
10use crate::type_aliases::type_variant::TypeVariantMember;
11
12pub trait TxnLogGetMutable<TID>: Sized {
13    unsafe fn get_mutable_from_log(log: &TxnLog, ty: TID) -> *mut Self;
14}
15
16impl<T: TypeVariantMember + 'static> TxnLogGetMutable<TypeId> for T {
17    unsafe fn get_mutable_from_log(log: &TxnLog, ty: TypeId) -> *mut Self {
18        let pending_ty = log.pending_type_id(ty);
19        if !pending_ty.is_null() {
20            return get_mutable_pending_type::<T>(pending_ty);
21        }
22
23        get_mutable_type_id::<T>(ty)
24    }
25}
26
27impl<T: TypePackVariantMember + 'static> TxnLogGetMutable<TypePackId> for T {
28    unsafe fn get_mutable_from_log(log: &TxnLog, tp: TypePackId) -> *mut Self {
29        let pending_tp = log.pending_type_pack_id(tp);
30        if !pending_tp.is_null() {
31            return get_mutable_pending_type_pack::<T>(pending_tp);
32        }
33
34        get_mutable_type_pack_id::<T>(tp)
35    }
36}
37
38impl TxnLog {
39    pub fn txn_log_get_mutable<T, TID>(&self, ty: TID) -> *mut T
40    where
41        T: TxnLogGetMutable<TID>,
42    {
43        unsafe { T::get_mutable_from_log(self, ty) }
44    }
45}