jeikabu / runng

MIT License
25 stars 3 forks source link

NngMsg API takes raw pointers... #23

Closed najamelan closed 5 years ago

najamelan commented 5 years ago

The methods on NngMsg take things like *const u8. For creating a msg, I have the impression we have no choice but to build the body with append for example.

The API would be much more rust idiomatic and convenient if you took &[u8] and converted to pointer internally. Also &[u8] has a len method, so the user would not have to supply a second parameter for size.

jeikabu commented 5 years ago

Makes sense. Initially I'd planned to keep NngMsg a 1:1 wrapper around nng's C methods and move the ergonomics to MsgBuilder. This is the approach taken in nng.Netcore, but it only makes sense there because managed-to-unmanaged calls have overhead and you'd want to avoid them completely. Since they should be zero-cost in rust, I might as well completely hide the C API. You can always call the original functions through runng-sys anyway. Thanks for pointing this out.

najamelan commented 5 years ago

Ok, sorry about this. I completely missed the MsgBuilder. I shall use that for now. That being said, yeah, converting the pointer should be without overhead and it would make the API cleaner.

jeikabu commented 5 years ago

Got rid of MsgBuilder and added append_slice to NngMsg