1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*!
# `::dyn_safe`
[](https://github.com/danielhenrymantilla/dyn_safe.rs)
[](https://crates.io/crates/dyn_safe)
[](https://docs.rs/dyn_safe)
[](https://gist.github.com/danielhenrymantilla/8e5b721b3929084562f8f65668920c33)
[](https://github.com/rust-secure-code/safety-dance/)
[](https://github.com/danielhenrymantilla/dyn_safe.rs/blob/master/LICENSE-ZLIB)
<!-- [](https://github.com/danielhenrymantilla/dyn_safe.rs/actions) -->
### Take control of the Semver hazard of the `dyn` safety of your traits!
##### Usage
1. `cargo add dyn_safe`, or add the following to your `Cargo.toml` file:
```toml
[dependencies]
dyn_safe = "x.y.z"
```
- where you can find the version using `cargo search dyn_safe`
1. Add the following to your `lib.rs` file:
```rust,ignore
#[macro_use]
extern crate dyn_safe;
```
1. Use `#[dyn_safe(true)]` or `#[dyn_safe(false)]` to, respectively,
assert that the trait object is `dyn`-safe or that the trait
object should not be `dyn`-safe.
- ```rust,compile_fail
# use ::dyn_safe::dyn_safe; macro_rules! ignore {($($t:tt)*) => ()} ignore! {
#[macro_use]
extern crate dyn_safe;
# }
#[dyn_safe(true)]
pub trait Foo {
fn whoops ();
}
```
```rust
# use ::dyn_safe::dyn_safe; macro_rules! ignore {($($t:tt)*) => ()} ignore! {
#[macro_use]
extern crate dyn_safe;
# }
#[dyn_safe(false)]
pub trait Foo {
fn ok ();
}
```
- ```rust,compile_fail
# use ::dyn_safe::dyn_safe; macro_rules! ignore {($($t:tt)*) => ()} ignore! {
#[macro_use]
extern crate dyn_safe;
# }
#[dyn_safe(false)]
pub trait Foo {
// …
}
let _: dyn Foo; // Whoops
```
```rust
# use ::dyn_safe::dyn_safe; macro_rules! ignore {($($t:tt)*) => ()} ignore! {
#[macro_use]
extern crate dyn_safe;
# }
#[dyn_safe(true)]
pub trait Foo {
// …
}
let _: dyn Foo; // Ok
```
*/
/// For a bug when cross-compiling
extern crate proc_macros;
pub use dyn_safe;
/// "Marker" (super-)trait used to opt-out of object safety.
pub