Skip to content

Commit 4b11798

Browse files
BennoLossinojeda
authored andcommitted
rust: pin-init: move proc-macro documentation into pin-init crate
Move the documentation of proc-macros from pin-init-internal into pin-init. This is because documentation can only reference types from dependencies and pin-init-internal cannot have pin-init as a dependency, as that would be cyclic. Signed-off-by: Benno Lossin <[email protected]> Reviewed-by: Fiona Behrens <[email protected]> Tested-by: Andreas Hindborg <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 86f7dac commit 4b11798

File tree

2 files changed

+114
-106
lines changed

2 files changed

+114
-106
lines changed

rust/pin-init/internal/src/lib.rs

Lines changed: 3 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,18 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

3-
/// Used to specify the pinning information of the fields of a struct.
4-
///
5-
/// This is somewhat similar in purpose as
6-
/// [pin-project-lite](https://crates.io/crates/pin-project-lite).
7-
/// Place this macro on a struct definition and then `#[pin]` in front of the attributes of each
8-
/// field you want to structurally pin.
9-
///
10-
/// This macro enables the use of the [`pin_init!`] macro. When pin-initializing a `struct`,
11-
/// then `#[pin]` directs the type of initializer that is required.
12-
///
13-
/// If your `struct` implements `Drop`, then you need to add `PinnedDrop` as arguments to this
14-
/// macro, and change your `Drop` implementation to `PinnedDrop` annotated with
15-
/// `#[`[`macro@pinned_drop`]`]`, since dropping pinned values requires extra care.
16-
///
17-
/// # Examples
18-
///
19-
/// ```ignore
20-
/// # #![feature(lint_reasons)]
21-
/// # use kernel::prelude::*;
22-
/// # use std::{sync::Mutex, process::Command};
23-
/// # use kernel::macros::pin_data;
24-
/// #[pin_data]
25-
/// struct DriverData {
26-
/// #[pin]
27-
/// queue: Mutex<KVec<Command>>,
28-
/// buf: KBox<[u8; 1024 * 1024]>,
29-
/// }
30-
/// ```
31-
///
32-
/// ```ignore
33-
/// # #![feature(lint_reasons)]
34-
/// # use kernel::prelude::*;
35-
/// # use std::{sync::Mutex, process::Command};
36-
/// # use core::pin::Pin;
37-
/// # pub struct Info;
38-
/// # mod bindings {
39-
/// # pub unsafe fn destroy_info(_ptr: *mut super::Info) {}
40-
/// # }
41-
/// use kernel::macros::{pin_data, pinned_drop};
42-
///
43-
/// #[pin_data(PinnedDrop)]
44-
/// struct DriverData {
45-
/// #[pin]
46-
/// queue: Mutex<KVec<Command>>,
47-
/// buf: KBox<[u8; 1024 * 1024]>,
48-
/// raw_info: *mut Info,
49-
/// }
50-
///
51-
/// #[pinned_drop]
52-
/// impl PinnedDrop for DriverData {
53-
/// fn drop(self: Pin<&mut Self>) {
54-
/// unsafe { bindings::destroy_info(self.raw_info) };
55-
/// }
56-
/// }
57-
/// # fn main() {}
58-
/// ```
59-
///
60-
/// [`pin_init!`]: ../kernel/macro.pin_init.html
61-
// ^ cannot use direct link, since `kernel` is not a dependency of `macros`.
3+
#[allow(missing_docs)]
624
#[proc_macro_attribute]
635
pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
646
pin_data::pin_data(inner, item)
657
}
668

67-
/// Used to implement `PinnedDrop` safely.
68-
///
69-
/// Only works on structs that are annotated via `#[`[`macro@pin_data`]`]`.
70-
///
71-
/// # Examples
72-
///
73-
/// ```ignore
74-
/// # #![feature(lint_reasons)]
75-
/// # use kernel::prelude::*;
76-
/// # use macros::{pin_data, pinned_drop};
77-
/// # use std::{sync::Mutex, process::Command};
78-
/// # use core::pin::Pin;
79-
/// # mod bindings {
80-
/// # pub struct Info;
81-
/// # pub unsafe fn destroy_info(_ptr: *mut Info) {}
82-
/// # }
83-
/// #[pin_data(PinnedDrop)]
84-
/// struct DriverData {
85-
/// #[pin]
86-
/// queue: Mutex<KVec<Command>>,
87-
/// buf: KBox<[u8; 1024 * 1024]>,
88-
/// raw_info: *mut bindings::Info,
89-
/// }
90-
///
91-
/// #[pinned_drop]
92-
/// impl PinnedDrop for DriverData {
93-
/// fn drop(self: Pin<&mut Self>) {
94-
/// unsafe { bindings::destroy_info(self.raw_info) };
95-
/// }
96-
/// }
97-
/// ```
9+
#[allow(missing_docs)]
9810
#[proc_macro_attribute]
9911
pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
10012
pinned_drop::pinned_drop(args, input)
10113
}
10214

103-
/// Derives the [`Zeroable`] trait for the given struct.
104-
///
105-
/// This can only be used for structs where every field implements the [`Zeroable`] trait.
106-
///
107-
/// # Examples
108-
///
109-
/// ```ignore
110-
/// use kernel::macros::Zeroable;
111-
///
112-
/// #[derive(Zeroable)]
113-
/// pub struct DriverData {
114-
/// id: i64,
115-
/// buf_ptr: *mut u8,
116-
/// len: usize,
117-
/// }
118-
/// ```
15+
#[allow(missing_docs)]
11916
#[proc_macro_derive(Zeroable)]
12017
pub fn derive_zeroable(input: TokenStream) -> TokenStream {
12118
zeroable::derive(input)

rust/pin-init/src/lib.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,117 @@ pub mod __internal;
218218
#[doc(hidden)]
219219
pub mod macros;
220220

221+
/// Used to specify the pinning information of the fields of a struct.
222+
///
223+
/// This is somewhat similar in purpose as
224+
/// [pin-project-lite](https://crates.io/crates/pin-project-lite).
225+
/// Place this macro on a struct definition and then `#[pin]` in front of the attributes of each
226+
/// field you want to structurally pin.
227+
///
228+
/// This macro enables the use of the [`pin_init!`] macro. When pin-initializing a `struct`,
229+
/// then `#[pin]` directs the type of initializer that is required.
230+
///
231+
/// If your `struct` implements `Drop`, then you need to add `PinnedDrop` as arguments to this
232+
/// macro, and change your `Drop` implementation to `PinnedDrop` annotated with
233+
/// `#[`[`macro@pinned_drop`]`]`, since dropping pinned values requires extra care.
234+
///
235+
/// # Examples
236+
///
237+
/// ```ignore
238+
/// # #![feature(lint_reasons)]
239+
/// # use kernel::prelude::*;
240+
/// # use std::{sync::Mutex, process::Command};
241+
/// # use kernel::macros::pin_data;
242+
/// #[pin_data]
243+
/// struct DriverData {
244+
/// #[pin]
245+
/// queue: Mutex<KVec<Command>>,
246+
/// buf: KBox<[u8; 1024 * 1024]>,
247+
/// }
248+
/// ```
249+
///
250+
/// ```ignore
251+
/// # #![feature(lint_reasons)]
252+
/// # use kernel::prelude::*;
253+
/// # use std::{sync::Mutex, process::Command};
254+
/// # use core::pin::Pin;
255+
/// # pub struct Info;
256+
/// # mod bindings {
257+
/// # pub unsafe fn destroy_info(_ptr: *mut super::Info) {}
258+
/// # }
259+
/// use kernel::macros::{pin_data, pinned_drop};
260+
///
261+
/// #[pin_data(PinnedDrop)]
262+
/// struct DriverData {
263+
/// #[pin]
264+
/// queue: Mutex<KVec<Command>>,
265+
/// buf: KBox<[u8; 1024 * 1024]>,
266+
/// raw_info: *mut Info,
267+
/// }
268+
///
269+
/// #[pinned_drop]
270+
/// impl PinnedDrop for DriverData {
271+
/// fn drop(self: Pin<&mut Self>) {
272+
/// unsafe { bindings::destroy_info(self.raw_info) };
273+
/// }
274+
/// }
275+
/// # fn main() {}
276+
/// ```
277+
///
278+
/// [`pin_init!`]: crate::pin_init
279+
pub use ::macros::pin_data;
280+
281+
/// Used to implement `PinnedDrop` safely.
282+
///
283+
/// Only works on structs that are annotated via `#[`[`macro@pin_data`]`]`.
284+
///
285+
/// # Examples
286+
///
287+
/// ```ignore
288+
/// # #![feature(lint_reasons)]
289+
/// # use kernel::prelude::*;
290+
/// # use macros::{pin_data, pinned_drop};
291+
/// # use std::{sync::Mutex, process::Command};
292+
/// # use core::pin::Pin;
293+
/// # mod bindings {
294+
/// # pub struct Info;
295+
/// # pub unsafe fn destroy_info(_ptr: *mut Info) {}
296+
/// # }
297+
/// #[pin_data(PinnedDrop)]
298+
/// struct DriverData {
299+
/// #[pin]
300+
/// queue: Mutex<KVec<Command>>,
301+
/// buf: KBox<[u8; 1024 * 1024]>,
302+
/// raw_info: *mut bindings::Info,
303+
/// }
304+
///
305+
/// #[pinned_drop]
306+
/// impl PinnedDrop for DriverData {
307+
/// fn drop(self: Pin<&mut Self>) {
308+
/// unsafe { bindings::destroy_info(self.raw_info) };
309+
/// }
310+
/// }
311+
/// ```
312+
pub use ::macros::pinned_drop;
313+
314+
/// Derives the [`Zeroable`] trait for the given struct.
315+
///
316+
/// This can only be used for structs where every field implements the [`Zeroable`] trait.
317+
///
318+
/// # Examples
319+
///
320+
/// ```ignore
321+
/// use kernel::macros::Zeroable;
322+
///
323+
/// #[derive(Zeroable)]
324+
/// pub struct DriverData {
325+
/// id: i64,
326+
/// buf_ptr: *mut u8,
327+
/// len: usize,
328+
/// }
329+
/// ```
330+
pub use ::macros::Zeroable;
331+
221332
/// Initialize and pin a type directly on the stack.
222333
///
223334
/// # Examples

0 commit comments

Comments
 (0)