mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Use intra doc links in the documentation of vtable and const-field-offset macro
This commit is contained in:
parent
973964c2e3
commit
390b838c21
7 changed files with 26 additions and 23 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Fixed `FieldOffsets` derive macro on non-pub structs when one of its pub field expose a private type
|
- 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
|
## [0.1.1] - 2021-08-16
|
||||||
|
|
|
@ -203,8 +203,9 @@ pub fn const_field_offset(input: TokenStream) -> TokenStream {
|
||||||
};
|
};
|
||||||
|
|
||||||
let doc = format!(
|
let doc = format!(
|
||||||
"Helper struct containing the offsets of the fields of the struct `{}`",
|
"Helper struct containing the offsets of the fields of the struct [`{}`]\n\n\
|
||||||
struct_name
|
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 {
|
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
|
// Build the output, possibly using quasi-quotation
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
///
|
|
||||||
/// Generated from the derive macro `const-field-offset::FieldOffsets`
|
|
||||||
#[allow(missing_docs, non_camel_case_types)]
|
#[allow(missing_docs, non_camel_case_types)]
|
||||||
#struct_vis struct #field_struct_name {
|
#struct_vis struct #field_struct_name {
|
||||||
#(#vis #fields : #crate_::FieldOffset<#struct_name, #types, #pin_flag>,)*
|
#(#vis #fields : #crate_::FieldOffset<#struct_name, #types, #pin_flag>,)*
|
||||||
|
|
|
@ -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 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]
|
#![no_std]
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ All notable changes to this crate will be documented in this file.
|
||||||
## [0.1.4] - Unreleased
|
## [0.1.4] - Unreleased
|
||||||
|
|
||||||
- Added `VrcMapped` and `VWeakMapped` to allow for references to objects that are reachable via VRc
|
- 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
|
## [0.1.3] - 2021-08-16
|
||||||
|
|
||||||
|
|
|
@ -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 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.
|
- 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.
|
to that field, and mutable accessor that ends with `_mut` returns a mutable reference.
|
||||||
- `as_ptr` returns a `*mut u8`
|
- `as_ptr` returns a `*mut u8`
|
||||||
- `get_vtable` Return a reference to the VTable so one can access the associated consts.
|
- `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(),
|
items: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let additional_doc =
|
let additional_doc = format!(
|
||||||
format!("\nNote: Was generated from the `#[vtable]` macro on `{}`", vtable_name);
|
"\nNote: Was generated from the [`#[vtable]`](vtable) macro on [`{}`]",
|
||||||
|
vtable_name
|
||||||
|
);
|
||||||
generated_trait
|
generated_trait
|
||||||
.attrs
|
.attrs
|
||||||
.append(&mut Attribute::parse_outer.parse2(quote!(#[doc = #additional_doc])).unwrap());
|
.append(&mut Attribute::parse_outer.parse2(quote!(#[doc = #additional_doc])).unwrap());
|
||||||
|
|
|
@ -12,11 +12,11 @@ This crate allows you to create ffi-friendly virtual tables.
|
||||||
|
|
||||||
## Features
|
## 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.
|
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.
|
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.
|
- Ability to store constants in a vtable.
|
||||||
- These constants can even be a field offset.
|
- 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);
|
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.
|
that `cbindgen` can see the actual vtable.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -76,7 +76,7 @@ pub use vtable_macro::*;
|
||||||
mod vrc;
|
mod vrc;
|
||||||
pub use 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.
|
/// Safety: The Target object needs to be implemented correctly.
|
||||||
/// And there should be a VTable::VTable::new<T> function that returns a
|
/// And there should be a VTable::VTable::new<T> function that returns a
|
||||||
|
@ -93,12 +93,12 @@ pub unsafe trait VTableMeta {
|
||||||
type VTable: 'static;
|
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.
|
/// It is implemented if the macro has a "drop" function.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// Only the `#[vtable]` macro should implement this trait.
|
/// Only the [`#[vtable]`](macro@vtable) macro should implement this trait.
|
||||||
pub unsafe trait VTableMetaDrop: VTableMeta {
|
pub unsafe trait VTableMetaDrop: VTableMeta {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// `ptr` needs to be pointing to a valid allocated pointer
|
/// `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.
|
/// 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)
|
/// implements the `VTableMetaDrop` trait for it)
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct VBox<T: ?Sized + VTableMetaDrop> {
|
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
|
But when using the generated `XxxVTable_static!` macro that is not possible and this macro can be
|
||||||
used instead.
|
used instead.
|
||||||
Note that the `downcast` will not work with references created with this macro.
|
Note that the `downcast` will not work with references created with this macro.
|
||||||
|
|
|
@ -15,7 +15,7 @@ use core::convert::TryInto;
|
||||||
use core::sync::atomic::AtomicU32;
|
use core::sync::atomic::AtomicU32;
|
||||||
use std::sync::atomic::Ordering;
|
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.
|
/// 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`
|
/// 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
|
/// 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
|
/// 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.
|
/// 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
|
/// - 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`.
|
/// safe to get a Pin reference with `borrow_pin`.
|
||||||
/// - It is safe to pass it across ffi boundaries.
|
/// - It is safe to pass it across ffi boundaries.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue