heinrich5991 / libtw2

Some Teeworlds stuff in Rust.™
Apache License 2.0
50 stars 16 forks source link

[RFC] demo: Replace 'static with explicit lifetime 'a #97

Closed Patiga closed 5 months ago

Patiga commented 6 months ago

Problem I want to solve

Currently, you can only pass 'static readers/writers into the demo readers/writers. This works for Files, but not for writing into Vec<u8>. As we require io::Seek for both reader and writer, we would not write into Vec<u8> directly, but a Cursor<&mut Vec<u8>> should work.

Why RFC

I'm not sure about the implications of this change. Introducing a lifetime typically makes using it more difficult. This is apparent with the lifetime issues that arose.

Issues

New lifetime issues which I wasn't able to solve, I guess I disagree with the compiler on some level.

  1. Weird lifetime issue in tools/demo_read_write.
  2. Lifetime issue in tools/teehistorian2demo, where I tried to actually write into a Cursor<Vec<u8>>. (I also tried Cursor<&mut Vec<u8>> and that didn't work either.
Patiga commented 6 months ago

The suggested changes solved all the issues :+1: This change did not require any changes in tools. It should only lessen the restriction on the parameter (and make the code a little more complicated).