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

Is it possible to parse into an already boxed struct? #2911

Closed
alexeysofin opened this issue Mar 20, 2025 · 2 comments
Closed

Is it possible to parse into an already boxed struct? #2911

alexeysofin opened this issue Mar 20, 2025 · 2 comments

Comments

@alexeysofin
Copy link

When parsing a large object, and then boxing it, rust will allocated the struct on stack and then copy it's contents to heap, with huge objects that can be problematic performance-wise, are there any solutions to this?

@oli-obk
Copy link
Member

oli-obk commented Mar 24, 2025

There is https://docs.rs/serde/latest/src/serde/de/mod.rs.html#572 which should allow you to do that, but you do need an already initialized object, and your data structures need to support this as the default just allocates on the stack first and moves the value over afterwards.

@alexeysofin
Copy link
Author

great, thank you!

@oli-obk oli-obk closed this as completed Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants