Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Dec 13, 2023
1 parent dc1d741 commit 0c040e1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
35 changes: 2 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,10 @@ macro_rules! cfg_futures {
}

mod object;
use core::any::Any;
use core::marker::PhantomData;

use handle::HandleGuard;

pub use self::object::Object;
pub use self::object::{AnyObject, Object};

mod handle;
pub use self::handle::Handle;
pub use self::handle::{Handle, HandleGuard};

cfg_rt!(
pub mod rt;
Expand All @@ -65,29 +60,3 @@ pub trait Signal<M>: Object {
pub trait Slot<M>: Object {
fn handle(&mut self, cx: Handle<Self>, msg: M);
}

pub trait AnyObject {
fn as_any(&self) -> &dyn Any;

fn as_any_mut(&mut self) -> &mut dyn Any;

fn start_any(&mut self, handle: HandleGuard);
}

impl<O: Object + 'static> AnyObject for O {
fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}

fn start_any(&mut self, handle: HandleGuard) {
let handle = Handle {
guard: handle,
_marker: PhantomData,
};
self.start(handle)
}
}
31 changes: 31 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::Handle;
use crate::handle::HandleGuard;
use core::any::Any;
use core::marker::PhantomData;

pub trait Object {
#[allow(unused_variables)]
Expand All @@ -13,3 +16,31 @@ pub trait Object {
}
);
}


pub trait AnyObject {
fn as_any(&self) -> &dyn Any;

fn as_any_mut(&mut self) -> &mut dyn Any;

fn start_any(&mut self, handle: HandleGuard);
}

impl<O: Object + 'static> AnyObject for O {
fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}

fn start_any(&mut self, handle: HandleGuard) {
let handle = Handle {
guard: handle,
_marker: PhantomData,
};
self.start(handle)
}
}

0 comments on commit 0c040e1

Please sign in to comment.