48
48
//! }
49
49
//! ```
50
50
51
- pub use byte_struct_derive:: * ;
51
+ pub use byte_struct_derive:: { ByteStruct , ByteStructBE , ByteStructLE } ;
52
52
53
53
/// A type that can be packed into or unpacked from fixed-size bytes, but the method is unknown yet.
54
54
pub trait ByteStructLen {
@@ -58,9 +58,9 @@ pub trait ByteStructLen {
58
58
59
59
/// A data structure that can be packed into or unpacked from raw bytes.
60
60
///
61
- /// This trait can be derived by either `#[derive(ByteStructLE)]` or `#[derive(ByteStructBE)]`.
62
- /// The difference between two macros is byte order specification. `LE` is for little-endian,
63
- /// and `BE` is for big-endian. All members of the struct to derive must implement `ByteStructUnspecifiedByteOrder`.
61
+ /// This trait can be derived by
62
+ /// [`#[derive(ByteStruct)]`](https://docs.rs/byte_struct_derive/*/byte_struct_derive/derive.ByteStruct.html).
63
+ ///
64
64
/// One can implement this trait for custom types in order to pack or unpack an object in a special way.
65
65
pub trait ByteStruct : ByteStructLen {
66
66
/// Packs the struct into raw bytes and write to a slice
@@ -78,23 +78,25 @@ pub trait ByteStruct: ByteStructLen {
78
78
/// This is also implemented for array types whose element type implements `ByteStructUnspecifiedByteOrder`
79
79
/// and whose size is between 1 and 32 (inclusive).
80
80
///
81
- /// This trait is automatically implemented for all types that implements `ByteStruct`.
82
- /// In this case, all members of `ByteStructUnspecifiedByteOrder` are direct wrappers of `ByteStruct` members.
81
+ /// This trait is automatically implemented for all types that implements [ `ByteStruct`] .
82
+ /// In this case, all members of `ByteStructUnspecifiedByteOrder` are direct wrappers of [ `ByteStruct`] members.
83
83
///
84
84
/// Members in this trait are meant to be called by byte_struct internal only.
85
85
/// They do not do what one might expect:
86
86
/// the byte orders specified in `read_bytes_default_*` / `write_bytes_default_*` functions
87
87
/// are only **default byte orders**.
88
- /// The default byte order is only repected when the type itself does not carry byte order specification
88
+ /// The default byte order is only respected when the type itself does not carry byte order specification
89
89
/// (e.g. primitive types).
90
- /// In contrast, since `ByteStruct` types always have fixed packing method,
90
+ /// In contrast, since [ `ByteStruct`] types always have fixed packing method,
91
91
/// the default byte order has no effect on them, and the three versions of read / write functions for them,
92
- /// `_default_le`, `_default_be` and no-spec from `ByteStruct`, behave exactly the same.
92
+ /// `_default_le`, `_default_be` and no-spec from [ `ByteStruct`] , behave exactly the same.
93
93
///
94
94
/// One can implement this trait for custom types in order to pack or unpack an object in a special way,
95
95
/// but only when the said type changes its packing method depending on the default byte order.
96
96
/// An example for this is a custom fixed-size large integer type.
97
- /// If the packing method is independent from the default byte order, please implement `ByteStruct` instead.
97
+ /// If the packing method is independent from the default byte order, please implement [`ByteStruct`] instead.
98
+ ///
99
+ /// [`ByteStruct`]: trait.ByteStruct.html
98
100
pub trait ByteStructUnspecifiedByteOrder : ByteStructLen {
99
101
/// Packs the object into raw bytes with little-endian as the default byte order
100
102
fn write_bytes_default_le ( & self , bytes : & mut [ u8 ] ) ;
@@ -110,22 +112,22 @@ pub trait ByteStructUnspecifiedByteOrder: ByteStructLen {
110
112
}
111
113
112
114
impl < T : ByteStruct > ByteStructUnspecifiedByteOrder for T {
113
- /// A wrapper of `ByteStruct::write_bytes`
115
+ /// A wrapper of [ `ByteStruct::write_bytes`](trait.ByteStruct.html#tymethod.write_bytes)
114
116
fn write_bytes_default_le ( & self , bytes : & mut [ u8 ] ) {
115
117
self . write_bytes ( bytes) ;
116
118
}
117
119
118
- /// A wrapper of `ByteStruct::read_bytes`
120
+ /// A wrapper of [ `ByteStruct::read_bytes`](trait.ByteStruct.html#tymethod.read_bytes)
119
121
fn read_bytes_default_le ( bytes : & [ u8 ] ) -> Self {
120
122
Self :: read_bytes ( bytes)
121
123
}
122
124
123
- /// A wrapper of `ByteStruct::write_bytes`
125
+ /// A wrapper of [ `ByteStruct::write_bytes`](trait.ByteStruct.html#tymethod.write_bytes)
124
126
fn write_bytes_default_be ( & self , bytes : & mut [ u8 ] ) {
125
127
self . write_bytes ( bytes) ;
126
128
}
127
129
128
- /// A wrapper of `ByteStruct::read_bytes`
130
+ /// A wrapper of [ `ByteStruct::read_bytes`](trait.ByteStruct.html#tymethod.read_bytes)
129
131
fn read_bytes_default_be ( bytes : & [ u8 ] ) -> Self {
130
132
Self :: read_bytes ( bytes)
131
133
}
@@ -452,17 +454,19 @@ bsa5!(1);
452
454
byte_struct_array ! ( 100 ) ;
453
455
byte_struct_array ! ( 3000 ) ;
454
456
455
- /// Generates a structure that implements `ByteStructUnspecifiedByteOrder` with bit field semantics.
457
+ /// Generates a structure that implements [ `ByteStructUnspecifiedByteOrder`] with bit field semantics.
456
458
///
457
459
/// The bit fields are packed to / unpacked from the base integer type,
458
- /// which is then packed / unpacked using the primitive type's `ByteStructUnspecifiedByteOrder` implementation.
460
+ /// which is then packed / unpacked using the primitive type's [ `ByteStructUnspecifiedByteOrder`] implementation.
459
461
/// Therefore, the byte order of bit fields is unspecified internally, and is only specified
460
- /// by the parent structure that derives `ByteStructLE`, `ByteStructBE` , just like all primitive
462
+ /// by the parent structure that derives [`ByteStruct`](trait.ByteStruct.html) , just like all primitive
461
463
/// types.
462
464
///
463
465
/// Note that the memory representation of the generated structure during runtime is NOT in bit field layout.
464
466
/// This macro only provides conversion method between the plain structure and the bit-field-packed bytes.
465
467
///
468
+ /// [`ByteStructUnspecifiedByteOrder`]: trait.ByteStructUnspecifiedByteOrder.html
469
+ ///
466
470
/// # Example
467
471
/// ```
468
472
/// bitfields!(
0 commit comments