JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

More restructuring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨10b7b7c

⁨giterated-runtime/giterated-abi/src/vtable/mod.rs⁩ - ⁨922⁩ bytes
Raw
1 use std::{marker::PhantomData, mem::transmute, ops::Deref};
2
3 pub mod object;
4 pub mod operation;
5 pub mod plugin;
6 pub mod plugin_initialization;
7 pub mod runtime;
8 mod setting;
9 mod value;
10
11 pub use object::*;
12 pub use setting::*;
13 pub use value::*;
14
15 pub trait ObjectABI {
16 type VTable;
17 }
18
19 #[repr(transparent)]
20 pub struct VTable<T: ObjectABI> {
21 _marker: PhantomData<T>,
22 }
23
24 impl<T: ObjectABI> VTable<T> {
25 /// Creates a new `VTable<T>` reference to a static vtable in memory.
26 ///
27 /// Might be unsafe? It seems like it should be safe...
28 pub const fn new<V>(vtable: &'static V) -> &'static Self {
29 // We're going to transmute the reference to the typed vtable to us
30 // which will probably be fine
31 unsafe { transmute(vtable) }
32 }
33 }
34
35 impl<T: ObjectABI> Deref for VTable<T> {
36 type Target = T::VTable;
37
38 fn deref(&self) -> &Self::Target {
39 unsafe { transmute(self) }
40 }
41 }
42