ashdnazg commented on PR #10431:
URL: https://github.com/apache/arrow-rs/pull/10431#issuecomment-5090855693

   Thanks for pinging me!
   
   Since I don't want to assume anything about the existing implementation and 
where the structs came from, I'm accessing the fields directly and I store the 
original `release` and `private_data` in my new private_data:
   ```rust
           let private_data = Box::new(PrivateData {
               original_private_data: schema.private_data,
               original_release: schema.release,
               // other stuff
           });
           schema.private_data = Box::into_raw(private_data) as *mut c_void;
           schema.release = Some(release_schema);
   ```
   
   My release function does what it needs with my private data, then restores 
the original release and private data, and finally calls the original release 
function:
   ```rust
           let private_data = unsafe { Box::from_raw(schema.private_data as 
*mut PrivateData) };
           schema.release = private_data.original_release;
           schema.private_data = private_data.original_private_data;
           // call release if not null
   ```
   
   So in my opinion getters and `unsafe` setters are the simplest approach that 
provides the most flexibility while keeping soundness of safe code.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to