Skip to content

Commit

Permalink
Remove unnecessary AsRef and AsMut
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvalencik committed Jun 3, 2024
1 parent af3e7d8 commit f2fad0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 45 deletions.
8 changes: 3 additions & 5 deletions crates/neon/src/context/internal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{cell::RefCell, ffi::c_void, mem::MaybeUninit};

use crate::{
context::{Cx, ModuleContext},
context::ModuleContext,
handle::Handle,
result::NeonResult,
sys::{self, raw},
Expand Down Expand Up @@ -46,10 +46,8 @@ impl Env {
}
}

pub trait ContextInternal<'cx>: AsRef<Cx<'cx>> + AsMut<Cx<'cx>> + Sized {
fn env(&self) -> Env {
self.as_ref().env()
}
pub trait ContextInternal<'cx>: Sized {
fn env(&self) -> Env;
}

fn default_main(mut cx: ModuleContext) -> NeonResult<()> {
Expand Down
52 changes: 12 additions & 40 deletions crates/neon/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,26 +233,14 @@ impl<'cx> Cx<'cx> {
_phantom_inner: PhantomData,
})
}
}

impl<'cx> ContextInternal<'cx> for Cx<'cx> {
fn env(&self) -> Env {
self.env
}
}

impl<'cx> AsRef<Cx<'cx>> for Cx<'cx> {
fn as_ref(&self) -> &Cx<'cx> {
self
}
}

impl<'cx> AsMut<Cx<'cx>> for Cx<'cx> {
fn as_mut(&mut self) -> &mut Cx<'cx> {
self
}
}

impl<'cx> ContextInternal<'cx> for Cx<'cx> {}

impl<'cx> Context<'cx> for Cx<'cx> {}

#[repr(C)]
Expand Down Expand Up @@ -644,18 +632,6 @@ impl<'cx> DerefMut for ModuleContext<'cx> {
}
}

impl<'cx> AsRef<Cx<'cx>> for ModuleContext<'cx> {
fn as_ref(&self) -> &Cx<'cx> {
self
}
}

impl<'cx> AsMut<Cx<'cx>> for ModuleContext<'cx> {
fn as_mut(&mut self) -> &mut Cx<'cx> {
self
}
}

impl<'cx> UnwindSafe for ModuleContext<'cx> {}

impl<'cx> ModuleContext<'cx> {
Expand Down Expand Up @@ -708,7 +684,11 @@ impl<'cx> ModuleContext<'cx> {
}
}

impl<'cx> ContextInternal<'cx> for ModuleContext<'cx> {}
impl<'cx> ContextInternal<'cx> for ModuleContext<'cx> {
fn env(&self) -> Env {
self.cx.env
}
}

impl<'cx> Context<'cx> for ModuleContext<'cx> {}

Expand Down Expand Up @@ -736,18 +716,6 @@ impl<'cx> DerefMut for FunctionContext<'cx> {
}
}

impl<'cx> AsRef<Cx<'cx>> for FunctionContext<'cx> {
fn as_ref(&self) -> &Cx<'cx> {
self
}
}

impl<'cx> AsMut<Cx<'cx>> for FunctionContext<'cx> {
fn as_mut(&mut self) -> &mut Cx<'cx> {
self
}
}

impl<'cx> UnwindSafe for FunctionContext<'cx> {}

impl<'cx> FunctionContext<'cx> {
Expand Down Expand Up @@ -862,6 +830,10 @@ impl<'cx> FunctionContext<'cx> {
}
}

impl<'cx> ContextInternal<'cx> for FunctionContext<'cx> {}
impl<'cx> ContextInternal<'cx> for FunctionContext<'cx> {
fn env(&self) -> Env {
self.cx.env
}
}

impl<'cx> Context<'cx> for FunctionContext<'cx> {}

0 comments on commit f2fad0c

Please sign in to comment.