Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Transferable trait #319

Merged
merged 5 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/multi_thread/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ pub enum Request {
GetDataFromServer,
}

impl Transferable for Request {}

#[derive(Serialize, Deserialize, Debug)]
pub enum Response {
DataFetched,
}

impl Transferable for Response {}

pub enum Msg {
Updating,
}
Expand Down
4 changes: 0 additions & 4 deletions examples/multi_thread/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ pub enum Request {
GetDataFromServer,
}

impl Transferable for Request {}

#[derive(Serialize, Deserialize, Debug)]
pub enum Response {
DataFetched,
}

impl Transferable for Response {}

pub enum Msg {
Updating,
}
Expand Down
4 changes: 0 additions & 4 deletions examples/multi_thread/src/native_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ pub enum Request {
GetDataFromServer,
}

impl Transferable for Request {}

#[derive(Serialize, Deserialize, Debug)]
pub enum Response {
DataFetched,
}

impl Transferable for Response {}

pub enum Msg {
Updating,
}
Expand Down
4 changes: 0 additions & 4 deletions examples/routing/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ where
BrowserNavigationRouteChanged((String, T)),
}

impl<T> Transferable for Route<T> where for<'de> T: Serialize + Deserialize<'de> {}

#[derive(Serialize, Deserialize, Debug)]
pub enum Request<T> {
/// Changes the route using a RouteInfo struct and alerts connected components to the route change.
Expand All @@ -82,8 +80,6 @@ pub enum Request<T> {
GetCurrentRoute,
}

impl<T> Transferable for Request<T> where for<'de> T: Serialize + Deserialize<'de> {}

/// The Router worker holds on to the RouteService singleton and mediates access to it.
pub struct Router<T>
where
Expand Down
21 changes: 5 additions & 16 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,25 @@ enum ToWorker<T> {
Destroy,
}

impl<T> Transferable for ToWorker<T> where T: Serialize + for<'de> Deserialize<'de> {}

#[derive(Serialize, Deserialize)]
enum FromWorker<T> {
/// Worker sends this message when `wasm` bundle has loaded.
WorkerLoaded,
ProcessOutput(HandlerId, T),
}

impl<T> Transferable for FromWorker<T> where T: Serialize + for<'de> Deserialize<'de> {}

/// Represents a message which you could send to an agent.
pub trait Transferable
where
Self: Serialize + for<'de> Deserialize<'de>,
{
}

trait Packed {
fn pack(&self) -> Vec<u8>;
fn unpack(data: &[u8]) -> Self;
}

impl<T: Transferable> Packed for T {
impl<T: Serialize + for<'de> Deserialize<'de>> Packed for T {
fn pack(&self) -> Vec<u8> {
bincode::serialize(&self).expect("can't serialize a transferable object")
bincode::serialize(&self).expect("can't serialize an agent message")
}

fn unpack(data: &[u8]) -> Self {
bincode::deserialize(&data).expect("can't deserialize a transferable object")
bincode::deserialize(&data).expect("can't deserialize an agent message")
}
}

Expand Down Expand Up @@ -658,9 +647,9 @@ pub trait Agent: Sized + 'static {
/// Type of an input messagae.
type Message;
/// Incoming message type.
type Input: Transferable;
type Input: Serialize + for<'de> Deserialize<'de>;
/// Outgoing message type.
type Output: Transferable;
type Output: Serialize + for<'de> Deserialize<'de>;

/// Creates an instance of an agent.
fn create(link: AgentLink<Self>) -> Self;
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ pub mod prelude {
pub mod worker {
pub use crate::agent::{
Agent, AgentLink, Bridge, Bridged, Context, Global, HandlerId, Job, Private, Public,
Transferable,
};
}
}
Expand Down
Empty file added src/prelude.rs
Empty file.