switch theme

Rust Learnings

Written on : 2024-08-27

Est. Reading time:

Rust learnings

byteorder, Cursor, buffer

  • You get the write trait only on Cursors that contain &mut reference of whatever it is holding.
  • If your Cursor contains &mut [u8] (slices are pointers to heaps vectors in rust), and the vector is 0 sized. All write will fail as there is no space on the heap to write to. And Cursor cannot extend a [u8] as they are simple slices
    • Instead, make a cursor of &mut Vec<u8> which will be grown as required by Cursor during write.
  • Cursors can be converted to a nice vector after all writes using get_ref().to_vec()