Skip to content

Commit 527a359

Browse files
Improve the way proc macros are documented
This moves documentation of derive macros from the trait to the reexport. And it removes the dirty hack for `mesh!`. This was possible because this issue was closed: rust-lang/rust#58700
1 parent 9e6ce72 commit 527a359

File tree

4 files changed

+195
-211
lines changed

4 files changed

+195
-211
lines changed

lox-macros/src/lib.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ mod derives;
1616
mod mesh;
1717

1818

19-
/// See [`lox::mesh_macro`][dummy] for documentation.
20-
///
21-
/// [dummy]: ../lox/macro.mesh_macro.html
19+
// See [`lox::mesh`][../lox/macro.mesh.html] for documentation.
2220
#[proc_macro]
2321
pub fn mesh(input: TokenStream) -> TokenStream {
2422
use crate::mesh::MeshInput;
@@ -30,12 +28,7 @@ pub fn mesh(input: TokenStream) -> TokenStream {
3028
}
3129

3230

33-
/// Custom derive for the `Empty` trait.
34-
///
35-
/// See [the documentation of the `Empty` trait in `lox`][trait] for more information
36-
/// about this derive.
37-
///
38-
/// [trait]: ../lox/traits/trait.Empty.html
31+
// See main crate (`lox`) for documentation.
3932
#[proc_macro_derive(Empty)]
4033
pub fn derive_empty(input: TokenStream) -> TokenStream {
4134
let input = syn::parse_macro_input!(input as DeriveInput);
@@ -45,12 +38,7 @@ pub fn derive_empty(input: TokenStream) -> TokenStream {
4538
}
4639

4740

48-
/// Custom derive for the `MemSink` trait.
49-
///
50-
/// See [the documentation of the `MemSink` trait in `lox`][trait] for more
51-
/// information about this derive.
52-
///
53-
/// [trait]: ../lox/io/trait.MemSink.html
41+
// See main crate (`lox`) for documentation.
5442
#[proc_macro_derive(MemSink, attributes(lox))]
5543
pub fn derive_mem_sink(input: TokenStream) -> TokenStream {
5644
let input = syn::parse_macro_input!(input as DeriveInput);
@@ -60,12 +48,7 @@ pub fn derive_mem_sink(input: TokenStream) -> TokenStream {
6048
.into()
6149
}
6250

63-
/// Custom derive for the `MemSource` trait.
64-
///
65-
/// See [the documentation of the `MemSource` trait in `lox`][trait] for more
66-
/// information about this derive.
67-
///
68-
/// [trait]: ../lox/io/trait.MemSource.html
51+
// See main crate (`lox`) for documentation.
6952
#[proc_macro_derive(MemSource, attributes(lox))]
7053
pub fn derive_mem_source(input: TokenStream) -> TokenStream {
7154
let input = syn::parse_macro_input!(input as DeriveInput);

src/io/mod.rs

Lines changed: 4 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,118 +1245,8 @@ where
12451245
///
12461246
/// # Deriving
12471247
///
1248-
/// You can easily derive this trait for your own types. To derive this trait,
1249-
/// you have to attach `#[derive(MemSink)]` to your struct definition (note:
1250-
/// currently, the trait can only be derived for structs with named fields).
1251-
/// You also have to annotate your fields with `#[lox(...)]` attributes to tell
1252-
/// the derive macro what a field should be used for. Example:
1253-
///
1254-
/// ```
1255-
/// use lox::{
1256-
/// MemSink, VertexHandle,
1257-
/// cgmath::Point3,
1258-
/// ds::HalfEdgeMesh,
1259-
/// map::DenseMap,
1260-
/// };
1261-
///
1262-
///
1263-
/// #[derive(MemSink)]
1264-
/// struct MyMesh {
1265-
/// #[lox(core_mesh)]
1266-
/// mesh: HalfEdgeMesh,
1267-
///
1268-
/// #[lox(vertex_position)]
1269-
/// positions: DenseMap<VertexHandle, Point3<f32>>,
1270-
/// }
1271-
/// ```
1272-
///
1273-
/// There is one required field: the core mesh field. That field's type has to
1274-
/// implement several mesh traits, in particular `MeshMut` and `TriMeshMut`.
1275-
/// You have to annotate that mesh with `#[lox(core_mesh)]`.
1276-
///
1277-
/// Additionally, you can have fields for each mesh property, like vertex
1278-
/// position or face colors. The type of those fields has to implement
1279-
/// `PropStoreMut` with a compatible element type. You have to annotate these
1280-
/// property fields with the corresponding attribute. The available properties
1281-
/// are:
1282-
///
1283-
/// - `vertex_position`
1284-
/// - `vertex_normal`
1285-
/// - `vertex_color`
1286-
/// - `face_normal`
1287-
/// - `face_color`
1288-
///
1289-
/// Furthermore, there are some configurations (like the cast mode) that can be
1290-
/// configured via `lox(...)` attributes as well. See below for more
1291-
/// information.
1292-
///
1293-
///
1294-
/// ### Cast modes
1295-
///
1296-
/// You can set a *cast mode* for each field. A `MemSink` has to be able to
1297-
/// "handle" any primitive type as the source is allowed to call the property
1298-
/// methods with any type. The sink can handle types either by casting or by
1299-
/// returning an error. The field's cast mode determines which casts are
1300-
/// allowed and which are not. Possible cast modes:
1301-
///
1302-
/// - `cast = "none"`
1303-
/// - `cast = "lossless"`
1304-
/// - `cast = "rounding"`
1305-
/// - `cast = "clamping"`
1306-
/// - `cast = "lossy"` (*default*)
1307-
///
1308-
/// The `none` mode does not allow casting at all. If the type provided by the
1309-
/// source does not match the type in your struct, an error is returned. All
1310-
/// other modes correspond to the cast modes in the [`cast`
1311-
/// module][crate::cast].
1312-
///
1313-
/// Note that the cast modes are used by `derive(MemSource)` as well.
1314-
///
1315-
/// You can specify the cast mode either per field or globally on the whole
1316-
/// struct. The mode of the struct applies to all fields that don't have a
1317-
/// field-specific mode.
1318-
///
1319-
/// ```
1320-
/// # use lox::{
1321-
/// # MemSink, VertexHandle,
1322-
/// # cgmath::{Point3, Vector3},
1323-
/// # ds::HalfEdgeMesh,
1324-
/// # map::DenseMap,
1325-
/// # };
1326-
/// #
1327-
/// #[derive(MemSink)]
1328-
/// #[lox(cast = "none")]
1329-
/// struct MyMesh {
1330-
/// #[lox(core_mesh)]
1331-
/// mesh: HalfEdgeMesh,
1332-
///
1333-
/// #[lox(vertex_position)]
1334-
/// positions: DenseMap<VertexHandle, Point3<f32>>,
1335-
///
1336-
/// #[lox(vertex_normal, cast = "lossy")]
1337-
/// normals: DenseMap<VertexHandle, Vector3<f32>>,
1338-
/// }
1339-
/// ```
1340-
///
1341-
/// In this example, the vertex positions inherit the "struct global" cast mode
1342-
/// (`none`), while the vertex normals override that mode to `lossy`.
1343-
///
1344-
///
1345-
/// ### Exact traits required for each field
1346-
///
1347-
/// Traits required for the `core_mesh` field:
1348-
/// - TODO
1349-
///
1350-
/// Traits required for property fields. For type `T` of the field:
1351-
/// - `T` must implement [`PropStoreMut`][crate::map::PropStoreMut] (with
1352-
/// fitting handle type). Additionally:
1353-
/// - For `vertex_position`: `T::Target` must implement
1354-
/// [`Pos3Like`][crate::prop::Pos3Like].
1355-
/// - For `*_normal`: `T::Target` must implement
1356-
/// [`Vec3Like`][crate::prop::Vec3Like].
1357-
/// - For `*_color`: `T::Target` must implement
1358-
/// [`ColorLike`][crate::prop::ColorLike] and `T::Target::Channel` must
1359-
/// implement [`Primitive`].
1248+
/// You can easily derive this trait for your own types. See [the derive
1249+
/// macro's documentation](../derive.MemSink.html) for more information.
13601250
pub trait MemSink {
13611251
// =======================================================================
13621252
// ===== Mesh connectivity
@@ -1606,52 +1496,8 @@ where
16061496
///
16071497
/// # Deriving
16081498
///
1609-
/// You can easily derive this trait for your own types. To derive this trait,
1610-
/// you have to attach `#[derive(MemSource)]` to your struct definition (note:
1611-
/// currently, the trait can only be derived for structs with named fields).
1612-
/// You also have to annotate your fields with `#[lox(...)]` attributes to tell
1613-
/// the derive macro what a field should be used for. Example:
1614-
///
1615-
/// ```
1616-
/// use lox::{
1617-
/// MemSource, VertexHandle,
1618-
/// cgmath::Point3,
1619-
/// ds::SharedVertexMesh,
1620-
/// map::DenseMap,
1621-
/// };
1622-
///
1623-
///
1624-
/// #[derive(MemSource)]
1625-
/// struct MyMesh {
1626-
/// #[lox(core_mesh)]
1627-
/// mesh: SharedVertexMesh,
1628-
///
1629-
/// #[lox(vertex_position)]
1630-
/// positions: DenseMap<VertexHandle, Point3<f32>>,
1631-
/// }
1632-
/// ```
1633-
///
1634-
/// Deriving this trait works very similar to deriving [`MemSink`]. See its
1635-
/// documentation for more information on the custom derive.
1636-
///
1637-
///
1638-
/// ### Exact traits required for each field
1639-
///
1640-
/// Traits required for the `core_mesh` field:
1641-
/// - TODO
1642-
///
1643-
/// Traits required for property fields. For type `T` of the field:
1644-
/// - `T` must implement [`PropStore`][crate::map::PropStore] (with fitting
1645-
/// handle type). Additionally:
1646-
/// - For `vertex_position`: `T::Target` must implement
1647-
/// [`Pos3Like`][crate::prop::Pos3Like] and `T::Target::Scalar` must
1648-
/// implement [`Primitive`].
1649-
/// - For `*_normal`: `T::Target` must implement
1650-
/// [`Vec3Like`][crate::prop::Vec3Like] and `T::Target::Scalar` must
1651-
/// implement [`Primitive`].
1652-
/// - For `*_color`: `T::Target` must implement
1653-
/// [`ColorLike`][crate::prop::ColorLike] and `T::Target::Channel` must
1654-
/// implement [`Primitive`].
1499+
/// You can easily derive this trait for your own types. See [the derive
1500+
/// macro's documentation](../derive.MemSource.html) for more information.
16551501
pub trait MemSource {
16561502
/// The type of the core mesh.
16571503
type CoreMesh: TriMesh + BasicAdj;

0 commit comments

Comments
 (0)