Skip to content

Commit 4a363ea

Browse files
committed
Add missing docs
1 parent 323ad23 commit 4a363ea

3 files changed

Lines changed: 63 additions & 16 deletions

File tree

src/abi.rs

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,74 @@ use core::{
99
pub enum Abi {
1010
/* universal */
1111
/// This is the same as `extern fn foo()`; whatever the default your C compiler supports.
12-
C { unwind: bool },
12+
C {
13+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
14+
unwind: bool
15+
},
1316
/// Usually the same as [`extern "C"`](Abi::C), except on Win32, in which case it's
1417
/// [`"stdcall"`](Abi::Stdcall), or what you should use to link to the Windows API itself.
15-
System { unwind: bool },
18+
System {
19+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
20+
unwind: bool
21+
},
1622

1723
/// The default ABI when you write a normal `fn foo()` in any Rust code.
1824
Rust,
1925

2026
/* arm */
2127
/// The default for ARM.
22-
Aapcs { unwind: bool },
28+
Aapcs {
29+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
30+
unwind: bool
31+
},
2332

2433
/* x86 */
2534
/// The default for `x86_32` C code.
26-
Cdecl { unwind: bool },
35+
Cdecl {
36+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
37+
unwind: bool
38+
},
2739
/// The default for the Win32 API on `x86_32`.
28-
Stdcall { unwind: bool },
40+
Stdcall {
41+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
42+
unwind: bool
43+
},
2944
/// The `fastcall` ABI.
30-
Fastcall { unwind: bool },
45+
Fastcall {
46+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
47+
unwind: bool
48+
},
3149
/// The Windows C++ ABI.
32-
Thiscall { unwind: bool },
50+
Thiscall {
51+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
52+
unwind: bool
53+
},
3354
/// The `vectorcall` ABI.
34-
Vectorcall { unwind: bool },
55+
Vectorcall {
56+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
57+
unwind: bool
58+
},
3559

3660
/* x86_64 */
3761
/// The default for C code on non-Windows `x86_64`.
38-
SysV64 { unwind: bool },
62+
SysV64 {
63+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
64+
unwind: bool
65+
},
3966
/// The default for C code on `x86_64` Windows.
40-
Win64 { unwind: bool },
67+
Win64 {
68+
/// Whether unwinding across this ABI boundary is allowed (`*-unwind`).
69+
unwind: bool
70+
},
4171
}
4272

4373
impl Abi {
74+
/// Canonicalize this ABI for the current target.
75+
///
76+
/// Maps aliases (e.g. `system`, `cdecl`) to the concrete ABI actually used on
77+
/// the current OS/architecture, following Rust compiler rules.
78+
///
79+
/// Returns [`None`] if this ABI is not supported on the current target.
4480
#[must_use]
4581
pub fn canonize(self, has_c_varargs: bool) -> Option<Abi> {
4682
// from https://github.com/rust-lang/rust/blob/4fa80a5e733e2202d7ca4c203c2fdfda41cfe7dc/compiler/rustc_target/src/spec/abi_map.rs#L79

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg_attr(nightly_build, fn_ptr_trait)]
22
#![cfg_attr(feature = "abi_vectorcall", feature(abi_vectorcall))]
3-
#![warn(clippy::pedantic)]
3+
#![warn(clippy::pedantic, missing_docs)]
44
#![no_std]
55

66
//! `fn-ptr` is a small utility crate that provides a [`FnPtr`] trait, implemented for all function pointer types:
@@ -117,6 +117,7 @@ pub use abi::Abi;
117117

118118
mod r#impl;
119119

120+
/// Module containing all marker types and traits.
120121
pub mod markers;
121122

122123
/// Prelude for this crate.

src/markers.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
/// Type-level marker trait for function arity, from [`A0`] to [`A12`].
12
pub trait Arity {
3+
/// Number of parameters for this arity.
24
const N: usize;
35
}
46
macro_rules! define_arity_marker {
57
($(($name:ident, $n:expr)),+ $(,)?) => {
68
$(
9+
#[doc = "Type-level marker for functions with exactly "]
10+
#[doc = stringify!($n)]
11+
#[doc = " parameters."]
712
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
813
pub struct $name;
914

@@ -29,12 +34,16 @@ define_arity_marker!(
2934
(A12, 12),
3035
);
3136

37+
/// Type-level marker trait for function safety, either [`Safe`] or [`Unsafe`].
3238
pub trait Safety {
39+
/// `true` for safe functions, `false` for unsafe ones.
3340
const IS_SAFE: bool;
3441
}
3542

43+
/// Marker type for safe functions.
3644
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3745
pub struct Safe;
46+
/// Marker type for unsafe functions.
3847
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3948
pub struct Unsafe;
4049

@@ -45,7 +54,7 @@ impl Safety for Unsafe {
4554
const IS_SAFE: bool = false;
4655
}
4756

48-
/// Type-level ABI marker trait.
57+
/// Type-level marker trait for function ABI.
4958
///
5059
/// Types implementing this trait represent a specific `extern "..."` ABI.
5160
///
@@ -62,6 +71,9 @@ pub trait Abi {
6271
macro_rules! define_abi_marker {
6372
($name:ident, $lit:literal) => {
6473
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
74+
#[doc = "Type-level marker for the `"]
75+
#[doc = $lit]
76+
#[doc = "` ABI."]
6577
pub struct $name;
6678

6779
impl Abi for $name {
@@ -149,12 +161,10 @@ macro_rules! arity_marker {
149161
#[doc(hidden)]
150162
#[macro_export]
151163
macro_rules! abi_marker {
152-
// Rust
164+
// Common
153165
("Rust") => {
154166
$crate::markers::Rust
155167
};
156-
157-
// Universal C / system
158168
("C") => {
159169
$crate::markers::C
160170
};
@@ -176,7 +186,7 @@ macro_rules! abi_marker {
176186
$crate::markers::AapcsUnwind
177187
};
178188

179-
// x86 (32-bit)
189+
// x86
180190
("cdecl") => {
181191
$crate::markers::Cdecl
182192
};

0 commit comments

Comments
 (0)