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

feat: deserialize requests #1351

Merged
merged 2 commits into from
Sep 24, 2024
Merged

feat: deserialize requests #1351

merged 2 commits into from
Sep 24, 2024

Conversation

prestwich
Copy link
Member

Motivation

Deserialize request objects

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm, pending @DaniPopes

Comment on lines 268 to 273
// SAFETY: params is a ZST, so it's safe to fail to initialize it
unsafe {
params = Some(std::mem::transmute(
MaybeUninit::<Params>::uninit().assume_init(),
))
}
Copy link
Member

@mattsse mattsse Sep 24, 2024

Choose a reason for hiding this comment

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

I believe this is sound, iirc this should also work

std::mem::zeroed::<T>()

Copy link
Member Author

Choose a reason for hiding this comment

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

changed it to this and removed unnecessary transmute

Comment on lines +280 to +281
meta: RequestMeta::new(method.unwrap(), id.unwrap_or(Id::None)),
params: params.unwrap(),
Copy link
Member

Choose a reason for hiding this comment

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

these are fine, because checked above

@mattsse
Copy link
Member

mattsse commented Sep 24, 2024

@prestwich clippy does not like this -.- perhaps this works MaybeUninit::<T>::zeroed().assume_init()

@DaniPopes
Copy link
Member

It's not UB if it's zero-sized, fixable by just allowing the lint and removing the transmute since that lint is valid

@prestwich
Copy link
Member Author

zeroed and uninit should be equivalent for a ZST, but zeroed won't trigger the lint, so I removed the transmute and changed to zeroed

@DaniPopes DaniPopes merged commit 12bf65a into main Sep 24, 2024
26 checks passed
@DaniPopes DaniPopes deleted the prestwich/deser-req branch September 24, 2024 20:42
lwedge99 pushed a commit to sentioxyz/alloy that referenced this pull request Oct 8, 2024
* feat: deserialize requests

* lint: clippy
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