-
Notifications
You must be signed in to change notification settings - Fork 172
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
[proc macros]: support generic type params #436
Conversation
fn subscribe_storage(&self, mut sink: SubscriptionSink, keys: Option<Vec<u8>>) { | ||
sink.send(&keys.unwrap_or_default()).unwrap(); | ||
fn subscribe_storage(&self, mut sink: SubscriptionSink, _keys: Option<Vec<ExampleStorageKey>>) { | ||
sink.send(&vec![[0; 32]]).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe produce a few more items here?
proc-macros/src/helpers.rs
Outdated
fn visit_return_type(&mut self, return_type: &'ast syn::ReturnType) { | ||
self.visiting_return_type = true; | ||
visit::visit_return_type(self, return_type); | ||
self.visiting_return_type = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here, I have a hard time understanding what visit::visit_return_type
does and why we need the true/false
stuff. Some docs would be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have "borrowed" this code from jsonrpc
and I think it's to make it possible to know whether it's a return type or param when visiting the Ident
in fn visit_ident
proc-macros/src/new/render_server.rs
Outdated
|
||
let where_clause = server_generate_where_clause(&self.trait_def); | ||
|
||
// NOTE(niklasad1): empty where clause is valid rust syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL too! (I do like how Rust syntax is generally very amenable to code gen)
Co-authored-by: David <dvdplm@gmail.com>
Co-authored-by: David <dvdplm@gmail.com>
fn subscribe_storage(&self, mut sink: SubscriptionSink, keys: Option<Vec<u8>>) { | ||
sink.send(&keys.unwrap_or_default()).unwrap(); | ||
fn subscribe_storage(&self, mut sink: SubscriptionSink, _keys: Option<Vec<ExampleStorageKey>>) { | ||
sink.send(&vec![[0; 32]]).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically, we don't have any compile time check that actually only Vec<Hash>
can sent over the sink because send has T: Serialize bound.... not sure if we want ensure that at compile-time
let mut sub = client.subscribe_storage(None).await.unwrap(); | ||
assert_eq!(Some(vec![]), sub.next().await.unwrap()); | ||
let mut sub: Subscription<Vec<ExampleHash>> = | ||
RpcClient::<ExampleHash, ExampleStorageKey>::subscribe_storage(&client, None).await.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annoying to have to add these type hints but I think the issue for that is that we implement the client trait for T and these are not known in this cause at least not ExampleStorageKey
^^
@dvdplm @jsdw @maciejhirsz can you have another look at this? I think it should ready. |
Co-authored-by: David <dvdplm@gmail.com>
Co-authored-by: David <dvdplm@gmail.com>
Co-authored-by: David <dvdplm@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, left a minor nitpick on the docs.
Co-authored-by: David <dvdplm@gmail.com>
…psee into na-proc-macros-generics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good (especially for proc macro code)! Especially as I'm not really familiar with this codebase yet, some docs explaining what the aims of the visitors are would be good, but yup, I'm happy with this!
So this the first step for support generic params on the
trait
in theproc macros
For now I have ignored the
JSON Map
support as it currently not is used that widely used at least by us (substrate etc) and looks quite annoying to fix theserde impls
In addition I added that our
proc macros
adds the required traits bounds under the hood, it's quite annoying the repeat those everywhere as user of the API. I think this should be it...Substrate companion: paritytech/substrate@dp-jsonrpsee-integration-2...na-jsonrpsee-proc-macros
Nice to have: