Skip to content

Use procedural macros #340

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

Merged
merged 88 commits into from
Jan 28, 2019
Merged

Use procedural macros #340

merged 88 commits into from
Jan 28, 2019

Conversation

ascjones
Copy link
Contributor

@ascjones ascjones commented Dec 6, 2018

Closes #66.

Replaces the build_rpc_trait! macro with a trait level #[rpc] attribute. e.g.

#[rpc]
pub trait Rpc {
	/// Returns a protocol version
	#[rpc(name = "protocolVersion")]
	fn protocol_version(&self) -> Result<String>;

	/// Adds two numbers and returns a result
	#[rpc(name = "add", alias("callAsyncMetaAlias"))]
	fn add(&self, _: u64, _: u64) -> Result<u64>;

	/// Performs asynchronous operation
	#[rpc(name = "callAsync")]
	fn call(&self, _: u64) -> FutureResult<String, Error>;
}

and pubsub:

#[rpc]
pub trait Rpc {
	type Metadata;

	/// Hello subscription
	#[pubsub(subscription = "hello", subscribe, name = "hello_subscribe", alias("hello_sub"))]
	fn subscribe(&self, _: Self::Metadata, _: typed::Subscriber<String>, _: u64);

	/// Unsubscribe from hello subscription.
	#[pubsub(subscription = "hello", unsubscribe, name = "hello_unsubscribe")]
	fn unsubscribe(&self, _: Option<Self::Metadata>, _: SubscriptionId) -> Result<bool>;
}

Example of converting parity-ethereum.

Tasks

  • Move public helper types currently in jsonrpc-macros, need to figure out where they should go
    • auto_args wrappers: can be done inline
    • delegates: move to core for now
    • pubsub: move to pubsub
    • Trailing replace with Option in last position
  • Optional metadata in unsubscribe Optional metadata for unsubscribe. #352
  • Copy tests from jsonrpc-macros and make them work
  • Fix bug with single parameter as per: 00056d9#diff-61e49682a8be86b7288c62de1399069fR91
  • Fix compilation error with single trailing arg
  • Test with existing projects:
    • parity-ethereum
    • substrate
  • Deprecate (rather than replace/remove) jsonrpc-macros with proc macros implementation currently in jsonrpc-derive. Need to find out how best to deprecate the macro or the entire crate.
  • Rust 2018 compatibility (fn arg names and use crate?)
  • Documentation!

Future Improvements

@ascjones ascjones changed the title [WIP] Use procedural macros Use procedural macros Jan 25, 2019
@ascjones
Copy link
Contributor Author

Now ready for full review @tomusdrw

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@tomusdrw tomusdrw merged commit ec5249e into master Jan 28, 2019
@tomusdrw tomusdrw deleted the aj-proc-macro branch January 28, 2019 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants