Skip to content

Commit

Permalink
Remove Transferable trait (yewstack#319)
Browse files Browse the repository at this point in the history
* remove transferable trait

* remove transferable from router example, run cargo fmt

* cargo fmt

* Remove Transferable from multi_thread example
  • Loading branch information
hgzimmerman authored and llebout committed Jan 20, 2020
1 parent 662ee4a commit 280eb2a
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 33 deletions.
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 message.
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.

0 comments on commit 280eb2a

Please sign in to comment.