Problem wrapping C object with multiple ownership modes

I'm wrapping a C object called Blob that can either borrow or own its data. What's the best way to provide an ergonomic wrapper around this object?

I've left the question vague to try to get a range of responses, feel free to ask for more info if necessary.

If the borrowed vs owned is known statically (e.g. some method returns always owned) then you can have two types Blob and BlobRef<'a> for owned and borrowed. There's foreign types crate for this.

If ownership can change at run time, then you'll need something like libstd's Cow for this, Cow<'a, Blob>.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.