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

Add a new-type pattern struct BoxedLibrary(Box<Library>) #28

Open
ClydeHobart opened this issue Nov 17, 2022 · 0 comments
Open

Add a new-type pattern struct BoxedLibrary(Box<Library>) #28

ClydeHobart opened this issue Nov 17, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ClydeHobart
Copy link
Owner

This should implement Serialize and Deserialize<'de> explicitly.

impl<'de> Deserialize<'de>:

let raw_mu_library: *mut MaybeUninit<Library> =
    // Safe: allocated from the `Layout`, and `MaybeUninit<Library>` has the same align and size by definition
    unsafe { std::alloc::alloc(std::alloc::Layout::new::<Library>()) as *mut MaybeUninit<Library> };

if raw_mu_library.is_null() {
    std::alloc::handle_alloc_error();
}

let mut box_mu_library: Box<MaybeUninit<Library>> =
    // Safe: see allocation and null handling above
    unsafe { Box::from_raw(raw_mu_library) };

Library::initialize_maybe_uninit(&mut box_mu_library);

let mut box_library: Box<Library> =
    // Safe: see initialization above
    unsafe { std::mem::transmute(box_mu_library) };

// ...

Deserialize Vec fields normally, but array fields should be deserialzed one f32 or Quat at a time, writing to the member field as if it were a 1D array.

impl Serialize

Serialize Vec fields normally, but array fields should be Serialzed one f32 or Quat at a time, writing from the member field as if it were a 1D array.

@ClydeHobart ClydeHobart self-assigned this Nov 17, 2022
@ClydeHobart ClydeHobart added the enhancement New feature or request label Nov 17, 2022
@ClydeHobart ClydeHobart changed the title Add a new-type pattern struct BoxedLibrary(Box<Library>) Add a new-type pattern struct BoxedLibrary(Box<Library>) Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant