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

Pass OwnedRpcParams to async methods #410

Merged
merged 8 commits into from
Jul 10, 2021

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented Jul 9, 2021

Pass OwnedRpcParams to async methods to allow deserializing to happen asynchronously as well.

Closes #408

@dvdplm dvdplm requested a review from maciejhirsz July 9, 2021 15:19
@dvdplm dvdplm self-assigned this Jul 9, 2021
utils/src/server/rpc_module.rs Outdated Show resolved Hide resolved
types/src/v2/params.rs Outdated Show resolved Hide resolved
@maciejhirsz
Copy link
Contributor

Might have to mess a bit more with lifetimes, or do an extra quasi iterator for parsing using next|optional_next, because as things are now this is not viable:

let a: &str = params.next();
let b: &str = params.next(); // a is using a lifetime that's bound to a mutable borrow, hence borrowck forbids this thinking it's aliasing

types/src/v2/params.rs Outdated Show resolved Hide resolved
Comment on lines +403 to +408
let params = RpcParams::new(Some(r#"["foo", "bar"]"#));
let mut seq = params.sequence();

assert_eq!(seq.next::<&str>().unwrap(), "foo");
assert_eq!(seq.next::<&str>().unwrap(), "bar");
assert!(seq.next::<&str>().is_err());
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the important test and the reason for adding a separate struct for handling sequence parsing: seq borrows the json from params, which allows it to produce slices with that lifetime, while &mut self borrows are transient.

@dvdplm dvdplm marked this pull request as ready for review July 10, 2021 11:59
@dvdplm dvdplm merged commit d5d67e9 into master Jul 10, 2021
@dvdplm dvdplm deleted the dp-async-methods-take-owned-rpcparams branch July 10, 2021 12:41
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.

Cannot parse RpcParams on another thread
2 participants