dbrgn / shtcx-rs

Platform agnostic Rust driver for the Sensirion SHTCx temperature/humidity sensors.
Apache License 2.0
13 stars 4 forks source link

Use ref for PhantomData #25

Closed dbrgn closed 4 years ago

dbrgn commented 4 years ago

From Rust docs[1]:

Adding a field of type PhantomData indicates that your type owns data of type T. This in turn implies that when your type is dropped, it may drop one or more instances of the type T. This has bearing on the Rust compiler's drop check analysis.

If your struct does not in fact own the data of type T, it is better to use a reference type, like PhantomData<&'a T> (ideally) or PhantomData<*const T> (if no lifetime applies), so as not to indicate ownership.

[1] https://doc.rust-lang.org/std/marker/struct.PhantomData.html#ownership-and-the-drop-check