Skip to content

Commit 86668b0

Browse files
committed
Update doc; update syn version
1 parent 9b89e7a commit 86668b0

File tree

3 files changed

+44
-28
lines changed

3 files changed

+44
-28
lines changed

byte_struct/src/lib.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
//! }
4949
//! ```
5050
51-
pub use byte_struct_derive::*;
51+
pub use byte_struct_derive::{ByteStruct, ByteStructBE, ByteStructLE};
5252

5353
/// A type that can be packed into or unpacked from fixed-size bytes, but the method is unknown yet.
5454
pub trait ByteStructLen {
@@ -58,9 +58,9 @@ pub trait ByteStructLen {
5858

5959
/// A data structure that can be packed into or unpacked from raw bytes.
6060
///
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+
///
6464
/// One can implement this trait for custom types in order to pack or unpack an object in a special way.
6565
pub trait ByteStruct: ByteStructLen {
6666
/// Packs the struct into raw bytes and write to a slice
@@ -78,23 +78,25 @@ pub trait ByteStruct: ByteStructLen {
7878
/// This is also implemented for array types whose element type implements `ByteStructUnspecifiedByteOrder`
7979
/// and whose size is between 1 and 32 (inclusive).
8080
///
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.
8383
///
8484
/// Members in this trait are meant to be called by byte_struct internal only.
8585
/// They do not do what one might expect:
8686
/// the byte orders specified in `read_bytes_default_*` / `write_bytes_default_*` functions
8787
/// 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
8989
/// (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,
9191
/// 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.
9393
///
9494
/// One can implement this trait for custom types in order to pack or unpack an object in a special way,
9595
/// but only when the said type changes its packing method depending on the default byte order.
9696
/// 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
98100
pub trait ByteStructUnspecifiedByteOrder: ByteStructLen {
99101
/// Packs the object into raw bytes with little-endian as the default byte order
100102
fn write_bytes_default_le(&self, bytes: &mut [u8]);
@@ -110,22 +112,22 @@ pub trait ByteStructUnspecifiedByteOrder: ByteStructLen {
110112
}
111113

112114
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)
114116
fn write_bytes_default_le(&self, bytes: &mut [u8]) {
115117
self.write_bytes(bytes);
116118
}
117119

118-
/// A wrapper of `ByteStruct::read_bytes`
120+
/// A wrapper of [`ByteStruct::read_bytes`](trait.ByteStruct.html#tymethod.read_bytes)
119121
fn read_bytes_default_le(bytes: &[u8]) -> Self {
120122
Self::read_bytes(bytes)
121123
}
122124

123-
/// A wrapper of `ByteStruct::write_bytes`
125+
/// A wrapper of [`ByteStruct::write_bytes`](trait.ByteStruct.html#tymethod.write_bytes)
124126
fn write_bytes_default_be(&self, bytes: &mut [u8]) {
125127
self.write_bytes(bytes);
126128
}
127129

128-
/// A wrapper of `ByteStruct::read_bytes`
130+
/// A wrapper of [`ByteStruct::read_bytes`](trait.ByteStruct.html#tymethod.read_bytes)
129131
fn read_bytes_default_be(bytes: &[u8]) -> Self {
130132
Self::read_bytes(bytes)
131133
}
@@ -452,17 +454,19 @@ bsa5!(1);
452454
byte_struct_array!(100);
453455
byte_struct_array!(3000);
454456

455-
/// Generates a structure that implements `ByteStructUnspecifiedByteOrder` with bit field semantics.
457+
/// Generates a structure that implements [`ByteStructUnspecifiedByteOrder`] with bit field semantics.
456458
///
457459
/// 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.
459461
/// 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
461463
/// types.
462464
///
463465
/// Note that the memory representation of the generated structure during runtime is NOT in bit field layout.
464466
/// This macro only provides conversion method between the plain structure and the bit-field-packed bytes.
465467
///
468+
/// [`ByteStructUnspecifiedByteOrder`]: trait.ByteStructUnspecifiedByteOrder.html
469+
///
466470
/// # Example
467471
/// ```
468472
/// bitfields!(

byte_struct_derive/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "byte_struct_derive"
3-
version = "0.4.0"
3+
version = "0.4.2"
44
authors = ["Weiyi Wang <[email protected]>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"
@@ -12,6 +12,6 @@ readme = "../README.md"
1212
proc-macro = true
1313

1414
[dependencies]
15-
syn = "0.14.4"
15+
syn = "0.15.0"
1616
quote = "0.6.3"
1717
proc-macro2 = "0.4"

byte_struct_derive/src/lib.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! # Derive macro for Byte Struct
2+
//!
3+
//! This crate provides macros for deriving the [`ByteStruct`] trait
4+
//! defined in the [`byte_struct` crate](https://docs.rs/byte_struct).
5+
//!
6+
//! See [`#[derive(ByteStruct)]`](derive.ByteStruct.html) for using the macro.
7+
//!
8+
//! [`ByteStruct`]: https://docs.rs/byte_struct/*/byte_struct/trait.ByteStruct.html
9+
110
#![recursion_limit = "128"]
211
extern crate proc_macro;
312

@@ -12,29 +21,32 @@ enum Endianness {
1221
Unspecified,
1322
}
1423

15-
/// Derives trait `ByteStruct` for a data structure.
24+
/// Derives trait [`ByteStruct`] for a data structure.
1625
///
17-
/// Requires all members to implement `ByteStructUnspecifiedByteOrder`.
18-
/// This includes most primitive types and nested structures with `ByteStruct` derived
19-
/// (because `ByteStruct` is automatically implemented for `ByteStructUnspecifiedByteOrder` types)
26+
/// Requires all members to implement [`ByteStructUnspecifiedByteOrder`].
27+
/// This includes most primitive types and nested structures with [`ByteStruct`] derived
28+
/// (because [`ByteStructUnspecifiedByteOrder`] is automatically implemented for [`ByteStruct`] types)
2029
///
2130
/// Byte order attributes `#[byte_struct_le]` or `#[byte_struct_be]` can be attached to individual fields
2231
/// and/or the entire structure.
2332
///
2433
/// When a byte order attribute are attached to a field, it selects which byte order version
25-
/// of `ByteStructUnspecifiedByteOrder` member functions to use on the field
34+
/// of [`ByteStructUnspecifiedByteOrder`] member functions to use on the field
2635
/// In other words, the attribute specifies the byte order on an byte-order-unspecified type.
27-
/// These attributes have no effect on fields that implements `ByteStruct`,
36+
/// These attributes have no effect on fields that implements [`ByteStruct`],
2837
/// because they always have the same byte packing method regardless of externally specified byte order.
2938
///
3039
/// When a byte order attribute is attached to the entire struct,
3140
/// it works as if it is attached to all fields that don't have byte order attributes.
3241
///
3342
/// If a field has no byte order attribute specified
3443
/// (either explicitly attached to the field or implicitly by the attribute on the entire structure),
35-
/// it must implement `ByteStruct` as well, so that its packing method is not byte-order-dependent.
44+
/// it must implement [`ByteStruct`] as well, so that its packing method is not byte-order-dependent.
3645
/// This is true for all `ByteStruct`-derived structures, but not for primitive types.
3746
///
47+
/// [`ByteStruct`]: https://docs.rs/byte_struct/*/byte_struct/trait.ByteStruct.html
48+
/// [`ByteStructUnspecifiedByteOrder`]: https://docs.rs/byte_struct/*/byte_struct/trait.ByteStructUnspecifiedByteOrder.html
49+
///
3850
/// ## Example
3951
/// ```
4052
/// #[derive(ByteStruct)]
@@ -84,7 +96,7 @@ pub fn byte_struct_macro_derive(input: TokenStream) -> TokenStream {
8496
byte_struct_macro_derive_impl(input, Endianness::Unspecified)
8597
}
8698

87-
/// Same effect as `#[derive(ByteStruct)] #[byte_struct_le]`
99+
/// Same effect as [`#[derive(ByteStruct)] #[byte_struct_le]`](derive.ByteStruct.html)
88100
///
89101
/// But doesn't support byte order attributes on fields
90102
#[deprecated]
@@ -93,7 +105,7 @@ pub fn byte_struct_le_macro_derive(input: TokenStream) -> TokenStream {
93105
byte_struct_macro_derive_impl(input, Endianness::Little)
94106
}
95107

96-
/// Same effect as `#[derive(ByteStruct)] #[byte_struct_be]`
108+
/// Same effect as [`#[derive(ByteStruct)] #[byte_struct_be]`](derive.ByteStruct.html)
97109
///
98110
/// But doesn't support byte order attributes on fields
99111
#[deprecated]

0 commit comments

Comments
 (0)