Some doc polish

This commit is contained in:
Olivier Goffart 2020-08-25 15:17:03 +02:00
parent 14fe897086
commit 697aa61a0c
3 changed files with 26 additions and 18 deletions

View file

@ -67,7 +67,7 @@ assert_eq!(FOO.get_byte_offset(), 4);
)]
/**
## limitations
## Limitations
Only work with named #[repr(C)] structures.
@ -95,23 +95,6 @@ let pin_box = Box::pin(Foo{field_1: 1, field_2: 2});
assert_eq!(*FIELD_2.apply_pin(pin_box.as_ref()), 2);
```
### `const-field-offset`
In case the `const-field-offset` crate is re-exported, it is possible to
specify the crate name using the `const_field_offset` attribute.
```rust
// suppose you re-export the const_field_offset create from a different module
mod xxx { pub use const_field_offset as cfo; }
#[repr(C)]
#[derive(xxx::cfo::FieldOffsets)]
#[const_field_offset(xxx::cfo)]
struct Foo {
field_1 : u8,
field_2 : u32,
}
```
### `pin_drop`
This attribute works like the `pin` attribute but it does not prevent a custom
@ -138,6 +121,23 @@ impl PinnedDrop for Foo {
}
```
### `const-field-offset`
In case the `const-field-offset` crate is re-exported, it is possible to
specify the crate name using the `const_field_offset` attribute.
```rust
// suppose you re-export the const_field_offset create from a different module
mod xxx { pub use const_field_offset as cfo; }
#[repr(C)]
#[derive(xxx::cfo::FieldOffsets)]
#[const_field_offset(xxx::cfo)]
struct Foo {
field_1 : u8,
field_2 : u32,
}
```
*/
#[proc_macro_derive(FieldOffsets, attributes(const_field_offset, pin, pin_drop))]
pub fn const_field_offset(input: TokenStream) -> TokenStream {

View file

@ -1,3 +1,10 @@
/*!
This crate expose the `FieldOffsets` derive macro, and the required.
It allows to get const FieldOffset for member of a `#[repr(C)]` struct.
The `FieldOffset` type is re-exported from the `field-offset` crate.
*/
#![no_std]
#[cfg(test)]

View file

@ -64,6 +64,7 @@ that `cbindgen` can see the actual vtable.
*/
#[doc(no_inline)]
pub use const_field_offset::*;
use core::marker::PhantomData;
use core::ops::{Deref, DerefMut, Drop};