mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
29 lines
528 B
Rust
29 lines
528 B
Rust
#![allow(clippy::inline_always)]
|
|
|
|
use std::cell::Ref;
|
|
|
|
use mlua::prelude::*;
|
|
use num::cast::AsPrimitive;
|
|
|
|
use super::NativeData;
|
|
|
|
// Cast T as U
|
|
|
|
#[inline(always)]
|
|
pub fn native_num_cast<T, U>(
|
|
from: &Ref<dyn NativeData>,
|
|
into: &Ref<dyn NativeData>,
|
|
) -> LuaResult<()>
|
|
where
|
|
T: AsPrimitive<U>,
|
|
U: 'static + Copy,
|
|
{
|
|
let from_ptr = unsafe { from.get_pointer().cast::<T>() };
|
|
let into_ptr = unsafe { into.get_pointer().cast::<U>() };
|
|
|
|
unsafe {
|
|
*into_ptr = (*from_ptr).as_();
|
|
}
|
|
|
|
Ok(())
|
|
}
|