Skip to content

Commit

Permalink
Add lifetime to System
Browse files Browse the repository at this point in the history
  • Loading branch information
KYovchevski committed Feb 1, 2024
1 parent 8cd130a commit 8e30383
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ impl AdlxFunctions {
}
}

pub struct AdlxHelper {
pub struct AdlxHelper<'lib> {
functions: AdlxFunctions,

system: super::system::System,
system: super::system::System<'lib>,

full_version: u64,
version: String,
}

impl AdlxHelper {
impl AdlxHelper<'_> {
pub fn new() -> Result<Self> {
let functions = unsafe { AdlxFunctions::load()? };

Expand All @@ -102,7 +102,7 @@ impl AdlxHelper {

System::from_raw(system)
};

Ok(AdlxHelper {
functions,

Expand All @@ -125,7 +125,7 @@ impl AdlxHelper {
}
}

impl Drop for AdlxHelper {
impl Drop for AdlxHelper<'_> {
fn drop(&mut self) {
// SAFETY: Nullity checked at load-time
let result = unsafe { (self.functions.terminate_fn.unwrap_unchecked())() };
Expand Down
12 changes: 6 additions & 6 deletions src/system.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::mem::MaybeUninit;
use std::{marker::PhantomData, mem::MaybeUninit};

use super::{
ffi,
Expand All @@ -15,12 +15,12 @@ use super::{
#[derive(Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXSystem")]
pub struct System(*mut ffi::IADLXSystem);
pub struct System<'lib>(*mut ffi::IADLXSystem, PhantomData<&'lib ()>);

unsafe impl Send for System {}
unsafe impl Sync for System {}
unsafe impl Send for System<'_> {}
unsafe impl Sync for System<'_> {}

impl System {
impl System<'_> {
/// Creates an [`Interface`] by taking ownership of the `raw` COM/ADLX interface pointer.
///
/// # Safety
Expand All @@ -29,7 +29,7 @@ impl System {
/// pointer. In other words, it must point to a vtable beginning with the
/// [`ffi::IADLXSystemVtbl`] function pointers.
pub(crate) unsafe fn from_raw(raw: *mut ffi::IADLXSystem) -> Self {
Self(raw)
Self(raw, PhantomData)
}

fn vtable(&self) -> &ffi::IADLXSystemVtbl {
Expand Down

0 comments on commit 8e30383

Please sign in to comment.