Use intra doc links in the documentation of vtable and const-field-offset macro

This commit is contained in:
Olivier Goffart 2021-11-09 17:37:31 +01:00
parent 973964c2e3
commit 390b838c21
7 changed files with 26 additions and 23 deletions

View file

@ -4,6 +4,7 @@
### Changed
- Fixed `FieldOffsets` derive macro on non-pub structs when one of its pub field expose a private type
- Added intra docs link in the generated documentation
## [0.1.1] - 2021-08-16

View file

@ -203,8 +203,9 @@ pub fn const_field_offset(input: TokenStream) -> TokenStream {
};
let doc = format!(
"Helper struct containing the offsets of the fields of the struct `{}`",
struct_name
"Helper struct containing the offsets of the fields of the struct [`{}`]\n\n\
Generated from the `#[derive(FieldOffsets)]` macro from the [`const-field-offset`]({}) crate",
struct_name, crate_
);
let (ensure_pin_safe, ensure_no_unpin, pin_flag, new_from_offset) = if !pin {
@ -253,8 +254,6 @@ pub fn const_field_offset(input: TokenStream) -> TokenStream {
// Build the output, possibly using quasi-quotation
let expanded = quote! {
#[doc = #doc]
///
/// Generated from the derive macro `const-field-offset::FieldOffsets`
#[allow(missing_docs, non_camel_case_types)]
#struct_vis struct #field_struct_name {
#(#vis #fields : #crate_::FieldOffset<#struct_name, #types, #pin_flag>,)*

View file

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

View file

@ -4,6 +4,7 @@ All notable changes to this crate will be documented in this file.
## [0.1.4] - Unreleased
- Added `VrcMapped` and `VWeakMapped` to allow for references to objects that are reachable via VRc
- Used intra-doc link in the generated documentation
## [0.1.3] - 2021-08-16

View file

@ -98,7 +98,7 @@ For the other fields:
The VRef/VRefMut/VBox structure will dereference to a type which has the following associated items:
- The functions from the vtable that have a VRef or VRefMut first parameter for self.
- For each `#[field_offset] attributes, a corresponding getter returns a reference
- For each `#[field_offset]` attributes, a corresponding getter returns a reference
to that field, and mutable accessor that ends with `_mut` returns a mutable reference.
- `as_ptr` returns a `*mut u8`
- `get_vtable` Return a reference to the VTable so one can access the associated consts.
@ -218,8 +218,10 @@ pub fn vtable(_attr: TokenStream, item: TokenStream) -> TokenStream {
items: Default::default(),
};
let additional_doc =
format!("\nNote: Was generated from the `#[vtable]` macro on `{}`", vtable_name);
let additional_doc = format!(
"\nNote: Was generated from the [`#[vtable]`](vtable) macro on [`{}`]",
vtable_name
);
generated_trait
.attrs
.append(&mut Attribute::parse_outer.parse2(quote!(#[doc = #additional_doc])).unwrap());

View file

@ -12,11 +12,11 @@ This crate allows you to create ffi-friendly virtual tables.
## Features
- A `#[vtable]` macro to annotate a VTable struct to generate the traits and structure
- A [`#[vtable]`](macro@vtable) macro to annotate a VTable struct to generate the traits and structure
to safely work with it.
- `VRef`/`VRefMut`/`VBox` types. They are fat reference/box types which wrap a pointer to
- [`VRef`]/[`VRefMut`]/[`VBox`] types. They are fat reference/box types which wrap a pointer to
the vtable, and a pointer to the object.
- `VRc`/`VWeak` types: equivalent to `std::rc::{Rc, Weak}` types but works with a vtable pointer.
- [`VRc`]/[`VWeak`] types: equivalent to `std::rc::{Rc, Weak}` types but works with a vtable pointer.
- Ability to store constants in a vtable.
- These constants can even be a field offset.
@ -56,9 +56,9 @@ let animal_box = VBox::<AnimalVTable>::new(Dog(42));
assert_eq!(animal_box.make_noise(2), 42 * 2);
```
The `#[vtable]` macro created the "Animal" trait.
The [`#[vtable]`](macro@vtable) macro created the "Animal" trait.
Note that the `#[vtable]` macro is applied to the VTable struct so
Note that the [`#[vtable]`](macro@vtable) macro is applied to the VTable struct so
that `cbindgen` can see the actual vtable.
*/
@ -76,7 +76,7 @@ pub use vtable_macro::*;
mod vrc;
pub use vrc::*;
/// Internal trait that is implemented by the `#[vtable]` macro.
/// Internal trait that is implemented by the [`#[vtable]`](macro@vtable) macro.
///
/// Safety: The Target object needs to be implemented correctly.
/// And there should be a VTable::VTable::new<T> function that returns a
@ -93,12 +93,12 @@ pub unsafe trait VTableMeta {
type VTable: 'static;
}
/// This trait is implemented by the `#[vtable]` macro.
/// This trait is implemented by the [`#[vtable]`](macro@vtable) macro.
///
/// It is implemented if the macro has a "drop" function.
///
/// # Safety
/// Only the `#[vtable]` macro should implement this trait.
/// Only the [`#[vtable]`](macro@vtable) macro should implement this trait.
pub unsafe trait VTableMetaDrop: VTableMeta {
/// # Safety
/// `ptr` needs to be pointing to a valid allocated pointer
@ -152,7 +152,7 @@ impl Inner {
///
/// The VBox implements Deref so one can access all the members of the vtable.
///
/// This is only valid if the VTable has a `drop` function (so that the `#[vtable]` macro
/// This is only valid if the VTable has a `drop` function (so that the [`#[vtable]`](macro@vtable) macro
/// implements the `VTableMetaDrop` trait for it)
#[repr(transparent)]
pub struct VBox<T: ?Sized + VTableMetaDrop> {
@ -391,9 +391,9 @@ impl<'a, T: ?Sized + VTableMeta> VRefMut<'a, T> {
}
}
/** Creates a `VRef` or a `VRefMut` suitable for an instance that implements the trait
/** Creates a [`VRef`] or a [`VRefMut`] suitable for an instance that implements the trait
When possible, `VRef::new` or `VRefMut::new` should be preferred, as they use a static vtable.
When possible, [`VRef::new`] or [`VRefMut::new`] should be preferred, as they use a static vtable.
But when using the generated `XxxVTable_static!` macro that is not possible and this macro can be
used instead.
Note that the `downcast` will not work with references created with this macro.

View file

@ -15,7 +15,7 @@ use core::convert::TryInto;
use core::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering;
/// This trait is implemented by the `#[vtable]` macro.
/// This trait is implemented by the [`#[vtable]`](macro@vtable) macro.
///
/// It is implemented if the macro has a "drop_in_place" function.
///
@ -91,11 +91,11 @@ impl<'vt, VTable: VTableMeta, X> VRcInner<'vt, VTable, X> {
/// A reference counted pointer to an object matching the virtual table `T`
///
/// Similar to [`std::rc::Rc`] where the `VTable` type parameter is a VTable struct
/// annotated with `#[vtable]`, and the `X` type parameter is the actual instance.
/// annotated with [`#[vtable]`](macro@vtable), and the `X` type parameter is the actual instance.
/// When `X` is the [`Dyn`] type marker, this means that the X is not known and the only
/// thing that can be done is to get a [`VRef<VTable>`] through the [`Self::borrow()`] function.
///
/// Other differences with the `std::rc::Rc` types are:
/// Other differences with the [`std::rc::Rc`] types are:
/// - It does not allow to access mutable reference. (No `get_mut` or `make_mut`), meaning it is
/// safe to get a Pin reference with `borrow_pin`.
/// - It is safe to pass it across ffi boundaries.