-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
One way serialize for subscriber type (#371)
* WIP: 2018 compile tests with one way serialization * WIP: attempting to get traitbounds to work with compiletests * Failing compile test for one way serialise Subscription type * One way Serialize for generic type only used in Subscriber
- Loading branch information
Showing
3 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
derive/tests/run-pass/pubsub-subscription-type-without-deserialize.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
extern crate serde; | ||
#[macro_use] | ||
extern crate serde_derive; | ||
extern crate jsonrpc_core; | ||
extern crate jsonrpc_pubsub; | ||
#[macro_use] | ||
extern crate jsonrpc_derive; | ||
|
||
use std::sync::Arc; | ||
use jsonrpc_core::Result; | ||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, Session, PubSubHandler}; | ||
|
||
#[rpc] | ||
pub trait Rpc<T> { | ||
type Metadata; | ||
|
||
/// Hello subscription | ||
#[pubsub(subscription = "hello", subscribe, name = "hello_subscribe", alias("hello_sub"))] | ||
fn subscribe(&self, _: Self::Metadata, _: Subscriber<T>); | ||
|
||
/// Unsubscribe from hello subscription. | ||
#[pubsub(subscription = "hello", unsubscribe, name = "hello_unsubscribe")] | ||
fn unsubscribe(&self, _: Option<Self::Metadata>, _: SubscriptionId) -> Result<bool>; | ||
} | ||
|
||
// One way serialization | ||
#[derive(Serialize)] | ||
struct SerializeOnly { | ||
foo: String, | ||
} | ||
|
||
struct RpcImpl; | ||
impl Rpc<SerializeOnly> for RpcImpl { | ||
type Metadata = Arc<Session>; | ||
|
||
fn subscribe(&self, _: Self::Metadata, _: Subscriber<SerializeOnly>) { | ||
unimplemented!(); | ||
} | ||
|
||
fn unsubscribe(&self, _: Option<Self::Metadata>, _: SubscriptionId) -> Result<bool> { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut io = PubSubHandler::default(); | ||
let rpc = RpcImpl; | ||
io.extend_with(rpc.to_delegate()); | ||
} |