The caller takes ownership of the returned resources, i.e., will have the responsibility in calling `bindings::dma_free_attrs`.
Hm, doesn't this violate RAII? Does this need to be public? The caller takes ownership of the returned resources, i.e., will have the responsibility in calling `bindings::dma_free_attrs`.
Hm, doesn't this violate RAII? Does this need to be public?It's C, you don't get any RAII.
E: I guess it sort of depends whether the handle is Copy semantics or not.
E2: I guess they're correctly leaking the resource, but I question whether they should, protections like that are kind of the whole point of using Rust to begin with.
Obviously forcing callers to free means adding lints and docs. Returning borrows leaves the likelihood of entering into explicit lifetimes hell and such in calling code.
A functional interface like (paraphrasing)
// pub fn apply_op(&mut self, FnMut(&mut T, &bindings::dma_addr_t... ))
Keeps pandora inside the box.Just like `Box::into_raw`, this method shouldn't be used in pure Rust code. It's only available for C FFI.
See Vec::into_raw_parts or Box::into_raw for an stdlib analogy.