instability_example/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![allow(dead_code)]
3
4//! This is an example library demonstrating various attributes from the [`instability`] crate.
5
6/// A stable type alias
7///
8/// This type alias is stable
9#[instability::stable(since = "v1.0.0")]
10pub type StableTypeAlias = u8;
11
12/// An unstable type alias
13///
14/// This type alias is unstable
15#[instability::unstable(feature = "type-alias")]
16pub type UnstableTypeAlias = u8;
17
18/// A stable constant
19///
20/// This constant is stable
21#[instability::stable(since = "v1.0.0")]
22pub const STABLE_CONSTANT: u8 = 42;
23
24/// An unstable constant
25///
26/// This constant is unstable
27#[instability::unstable(feature = "constant")]
28pub const UNSTABLE_CONSTANT: u8 = 42;
29
30/// A stable static
31///
32/// This static is stable
33#[instability::stable(since = "v1.0.0")]
34pub static STABLE_STATIC: u8 = 42;
35
36/// An unstable static
37///
38/// This static is unstable
39#[instability::unstable(feature = "static")]
40pub static UNSTABLE_STATIC: u8 = 42;
41
42/// A stable function
43///
44/// This function is stable
45#[instability::stable(since = "v1.0.0")]
46pub fn stable_function() {
47 unimplemented!()
48}
49
50/// An unstable function
51///
52/// This function is unstable
53#[instability::unstable(feature = "function")]
54pub fn unstable_function() {
55 unimplemented!()
56}
57
58/// A stable struct
59///
60/// This struct is stable
61#[instability::stable(since = "v1.0.0")]
62pub struct StableStruct {
63 pub x: u8,
64}
65
66impl StableStruct {
67 /// An unstable method
68 ///
69 /// This method is unstable
70 #[instability::unstable(feature = "method")]
71 pub fn unstable_method(&self) {
72 unimplemented!()
73 }
74
75 /// A stable method
76 ///
77 /// This method is stable
78 #[instability::stable(since = "v1.0.0")]
79 pub fn stable_method(&self) {
80 unimplemented!()
81 }
82}
83
84/// An unstable struct
85///
86/// This struct is unstable
87#[instability::unstable(feature = "struct")]
88pub struct UnstableStruct {
89 pub x: u8,
90}
91
92impl UnstableStruct {
93 /// An unstable method
94 ///
95 /// This method is unstable
96 #[instability::unstable(feature = "method")]
97 pub fn unstable_method(&self) {
98 unimplemented!()
99 }
100
101 /// A stable method
102 ///
103 /// This method is stable
104 #[allow(
105 unreachable_pub,
106 // reason = "The unstable macros cannot make the method pub(crate)"
107 )]
108 #[instability::stable(since = "v1.0.0")]
109 pub fn stable_method(&self) {
110 unimplemented!()
111 }
112}
113
114/// An unstable struct with an issue link
115///
116/// This struct is unstable and has an issue link.
117#[instability::unstable(feature = "struct-with-issue", issue = "#123")]
118pub struct UnstableStructWithIssue {
119 pub x: u8,
120}
121
122/// A stable trait
123///
124/// This trait is stable
125#[instability::stable(since = "v1.0.0")]
126pub trait StableTrait {
127 /// A stable trait method
128 ///
129 /// This method is stable.
130 fn stable_trait_method(&self) {
131 unimplemented!()
132 }
133
134 // Not yet supported
135 // /// An unstable trait method
136 // ///
137 // /// This method is unstable.
138 // #[instability::unstable(feature = "trait-method")]
139 // fn unstable_trait_method(&self);
140}
141
142#[instability::stable(since = "v1.0.0")]
143impl StableTrait for StableStruct {}
144
145/// An unstable trait
146///
147/// This trait is unstable
148#[instability::unstable(feature = "trait")]
149pub trait UnstableTrait {
150 /// A stable trait method
151 ///
152 /// This method is stable.
153 fn stable_trait_method(&self) {
154 unimplemented!()
155 }
156
157 // Not yet supported
158 // /// An unstable trait method
159 // ///
160 // /// This method is not implemented yet.
161 // #[instability::unstable(feature = "trait-method")]
162 // fn unstable_trait_method(&self);
163}
164
165#[instability::unstable(feature = "trait")]
166impl UnstableTrait for StableStruct {}
167
168/// A stable enum
169///
170/// This enum is stable.
171#[instability::stable(since = "v1.0.0")]
172pub enum StableEnum {
173 /// An enum variant
174 ///
175 /// This variant is stable.
176 Variant,
177}
178
179/// An unstable enum
180///
181/// This enum is unstable.
182#[instability::unstable(feature = "enum")]
183pub enum UnstableEnum {
184 /// An enum variant
185 ///
186 /// This variant is stable.
187 Variant,
188 // Not yet supported
189 // /// An unstable enum variant
190 // ///
191 // /// This variant is not implemented yet.
192 // #[instability::unstable(feature = "enum-variant")]
193 // UnstableVariant,
194}
195
196/// A stable module
197///
198/// This module is stable.
199#[instability::stable(since = "v1.0.0")]
200pub mod stable {
201 /// A stable function
202 ///
203 /// This function is stable.
204 pub fn stable_function() {
205 unimplemented!()
206 }
207
208 /// An unstable function
209 ///
210 /// This function is unstable.
211 #[instability::unstable(feature = "function")]
212 pub fn unstable_function() {
213 unimplemented!()
214 }
215}
216
217/// An unstable module
218///
219/// This module is unstable.
220#[instability::unstable(feature = "module")]
221pub mod unstable {
222 /// A stable function
223 ///
224 /// This function is stable.
225 #[instability::stable(since = "v1.0.0")]
226 pub fn stable_function() {
227 unimplemented!()
228 }
229
230 /// An unstable function
231 ///
232 /// This function is unstable.
233 #[instability::unstable(feature = "function")]
234 pub fn unstable_function() {
235 unimplemented!()
236 }
237}
238
239/// A private module
240///
241/// This module is private.
242mod private {
243 /// A private function
244 ///
245 /// This function is private.
246 pub fn private_function() {
247 unimplemented!()
248 }
249
250 /// An unstable private function
251 ///
252 /// This function is unstable.
253 #[instability::unstable(feature = "private-function")]
254 pub fn unstable_private_function() {
255 unimplemented!()
256 }
257}
258
259/// A stable re-export of a private stable item
260///
261/// This re-export is stable.
262pub use private::private_function as stable_reexport;
263
264/// An unstable re-export of a private stable item
265///
266/// This re-export is unstable.
267#[instability::unstable(feature = "reexport")]
268pub use private::private_function as unstable_reexport;
269
270// This does not work as the unstable_private_function is only public within the crate and cannot
271// be re-exported
272// /// A stable reexport of a private unstable item
273// ///
274// /// This export is stable.
275// pub use private::unstable_private_function as stable_unstable_reexport;
276
277/// An unstable reexport of a private unstable item
278///
279/// This export is unstable. The availability section on this will be appended to the availability
280/// section of the unstable_private_function, which will look odd. Consider avoiding re-exporting
281/// unstable items like this, and instead only mark the re-export itself as unstable.
282#[instability::unstable(feature = "reexport")]
283pub use private::unstable_private_function as unstable_unstable_export;