So the question is in the context of reddit discussions on https://www.reddit.com/r/rust/comments/fr50vl/r2_a_router_in_rust/ - where [BigHandLittleSlap] pointed out that the way I let applications have mutating access to packet buffers is terrible - https://github.com/gopakumarce/R2/blob/4457cb0c4fdb14f8aad3d2da46cd5e5524f29902/packet/src/lib.rs#L57
And obviously i'll be more than happy to correct it, can someone tell me whats the right way to do it ? This is what I responded there
And this was my thought process behind it. There are two ways to give applications a way to write into the packet
- Supply their own data buffer which gets copied into the packet
- Give them access to the packet but with bounds
I initially started off with #1 - but having copies of hundreds of bytes of data for every packet just wont cut it for performance. My "assumption" was that since I am providing a slice to the apps, theres no way they can overrun it/overwrite it and hence that should be acceptable.
I can be very wrong, and will be very glad to accept feedbacks on whats the right mechanism, and ill rework it