flatbuffers: [rust] Generated enums can cause undefined behavior

Just remembered that a discriminant absent from an C-like enum is considered undefined behaviour in rust. This means that all currently generated enums could potentially cause undefined behavior if someone adds a new enum field and sends that buffer to someone using a older version of the schema.

I think the ideal solution would be to use a standard enums and add the appropriate TryFrom implementation (e.g. TryFrom<u8>). Maybe we should returned the unmatched integer as the error type.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 28 (20 by maintainers)

Most upvoted comments

Yeah eventually, I’ll find the time.

@jean-airoldie, @rw I have prepared a solution for this and #5581 issues. A draft of Optional enums.

This is my first experience with Rust. If this is can be useful I will fix all notes and prepare PR. This code doesn’t cover bit_flags and has a problem with re-export of crates (I expect that dependencies resolution should be transitive but it doesn’t).

@jean-airoldie I get you. Thank you for the detailed explanation. I will try this solution.

Sure I’ll do that.