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

ambee/giterated

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

Pre vtable changes

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨d17a4b2

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