File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1285,6 +1285,26 @@ pub unsafe trait Immutable {
1285
1285
/// }
1286
1286
/// ```
1287
1287
///
1288
+ /// # Portability
1289
+ ///
1290
+ /// To ensure consistent endianness for enums with multi-byte representations,
1291
+ /// explicitly specify and convert each discriminant using `.to_le()` or
1292
+ /// `.to_be()`; e.g.:
1293
+ ///
1294
+ /// ```
1295
+ /// # use zerocopy_derive::TryFromBytes;
1296
+ /// // `DataStoreVersion` is encoded in little-endian.
1297
+ /// #[derive(TryFromBytes)]
1298
+ /// #[repr(u32)]
1299
+ /// pub enum DataStoreVersion {
1300
+ /// /// Version 1 of the data store.
1301
+ /// V1 = 9u32.to_le(),
1302
+ ///
1303
+ /// /// Version 2 of the data store.
1304
+ /// V2 = 10u32.to_le(),
1305
+ /// }
1306
+ /// ```
1307
+ ///
1288
1308
/// [safety conditions]: trait@TryFromBytes#safety
1289
1309
#[ cfg( any( feature = "derive" , test) ) ]
1290
1310
#[ cfg_attr( doc_cfg, doc( cfg( feature = "derive" ) ) ) ]
You can’t perform that action at this time.
0 commit comments