rust-pcap / pcap

Rust language pcap library
Apache License 2.0
617 stars 142 forks source link

Concerning use of empty enums for opaque types #358

Open FeldrinH opened 3 months ago

FeldrinH commented 3 months ago

pcap_t and pcap_dumper_t seem to be represented by empty enums on the Rust side. According to the Rustonomicon this is a bad idea.

From https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs:

Notice that it is a really bad idea to use an empty enum as FFI type. The compiler relies on empty enums being uninhabited, so handling values of type &Empty is a huge footgun and can lead to buggy program behavior (by triggering undefined behavior).

Stargateur commented 3 months ago

And according to C standard having an empty array is completely impossible yet the Rustonomicon put a empty array in a struct with repr(C).

Anyway, I have nothing against use a struct instead.