Do not take data ownership on put() and get()
put() and get() with payload (planned future release) should be able to accept a reference to the payload.
It seems there is not actual need for taking the ownership of user data to accomplish put() and get() operations.
Therefore, it would be more user-friendly to not take the ownership of user data in such a way to simplify user's memory management and reuse.
Not taking the ownership implies taking a reference to the object/buffer passed by the user. In Rust, a reference needs to be valid throughout the lifetime of the object so as to guarantee memory safety. However, ensuring the validity and making the borrow checker happy for those references, it's a very challenging task when operating in a async environment like the one in zenoh. E.g.:
- user's messages could be routed both to remote AND local subscribers
- subscribers could be callback- or stream-based
- boundaries between threads and tasks are hard to determine at compile time
Therefore, at the moment we don't really have a solution but to take ownership of data to enforce memory safety.
Recently, a new buffer interface has been merged: https://github.com/eclipse-zenoh/zenoh/pull/206
However, ZBuf and WBuf still rely on the old implementation and we don't have a clear way how to integrate non-static references to user's buffers.
A future refactoring of ZBuf and WBuf might enlighten us how to not take data ownership on put() and get().