darfink / region-rs

A cross-platform virtual memory API written in Rust
https://darfink.github.io/region-rs/
MIT License
119 stars 23 forks source link

`into_raw_parts` and `from_raw_parts` for `Allocation`s #30

Closed JieningYu closed 5 months ago

JieningYu commented 5 months ago

Freeing an allocation requires dropping an Allocation value, but there's no way to create a new Allocation from raw parts, unsafely.

This pull request introduces the function (with into_raw_parts), which is similar with Vec::from_raw_parts.

darfink commented 5 months ago

Thanks for the PR! I've never come across a use case for this myself, but it's a reasonable addition (especially considering it being somewhat analogous to Vec's counterpart).