macro_rules! unsafe_getter {
($struct:ident, $attribute_name:meta, $attribute_type:ty) => {
impl $struct {
paste::paste! {
#[doc = "Returns a mutable reference to the field `" $attribute_name "` of type [`" $attribute_type "`]."]
pub unsafe fn [<get_ $attribute_type>](&mut self) -> &mut $attribute_type {
&mut self.$attribute_name
}
}
}
};
}
macro_rules! unsafe_getter_mod {
($struct:ident, $attribute_name:meta, $attribute_type:ident) => {
impl $struct {
paste::paste! {
#[doc = "Returns a mutable reference to the field `" $attribute_name "` of type [`" $attribute_type "`]."]
pub unsafe fn [<get_ $attribute_type>](&mut self) -> &mut $attribute_type {
std::rc::Rc::<$attribute_type>::get_mut(&mut self.$attribute_name).unwrap()
}
}
}
};
}
macro_rules! unsafe_getter_indirect {
($struct:ident, $attribute_name:meta, $function_name:ident, $attribute_type:ty) => {
impl $struct {
paste::paste! {
#[doc = "Returns a mutable reference to the underlying [`" $attribute_type "`] by calling `" $function_name "` on `" $attribute_name "`."]
pub unsafe fn [<get_ $attribute_type>](&mut self) -> &mut $attribute_type {
unsafe { self.$attribute_name.$function_name() }
}
}
}
};
}
pub(crate) use unsafe_getter;
pub(crate) use unsafe_getter_indirect;
pub(crate) use unsafe_getter_mod;
macro_rules! unsafe_setter {
($struct:ident, $attribute_name:meta, $attribute_type:ty, $clear_function:ident) => {
impl $struct {
paste::paste! {
#[doc = "Sets the field `" $attribute_name "` of type [`" $attribute_type "`] to `flint_struct`."]
pub unsafe fn [<set_ $attribute_type>](&mut self, flint_struct: $attribute_type) {
unsafe { $clear_function(&mut self.$attribute_name) };
self.$attribute_name = flint_struct;
}
}
}
};
}
macro_rules! unsafe_setter_indirect {
($struct:ident, $attribute_name:meta, $function_name:ident, $attribute_type:ty) => {
impl $struct {
paste::paste! {
#[doc = "Sets the field [`" $attribute_type "`] to `flint_struct` by calling `" $function_name "` on `" $attribute_name "`."]
pub unsafe fn [<set_ $attribute_type>](&mut self, flint_struct: $attribute_type) {
unsafe { self.$attribute_name.$function_name(flint_struct) }
}
}
}
};
}
pub(crate) use unsafe_setter;
pub(crate) use unsafe_setter_indirect;