Untitled Project
outer_line_doc_comments.rs
Source file coverage
Path:
outer_line_doc_comments.rs
Lines:
332
Non-empty lines:
291
Non-empty lines covered with requirements:
271 / 291 (93.1%)
Functions:
59
Functions covered by requirements:
56 / 59 (94.9%)
1
#![feature(extern_types, stmt_expr_attributes, trait_alias)]
2
 
3
/// Top-level const with random docs:
4
/// @relation(RUST-OUTER-LINE-DOC)
5
/// quantum cascade amplifier
6
pub const MAGIC_NUMBER: u32 = 42;
7
 
8
/// Static item with random docs:
9
/// @relation(RUST-OUTER-LINE-DOC)
10
/// nebula crystalline matrix
11
pub static GLOBAL_STATE: &str = "initialized";
12
 
13
/// Type alias with random docs:
14
/// @relation(RUST-OUTER-LINE-DOC)
15
/// temporal flux capacitor
16
pub type CustomResult<T> = Result<T, Box<dyn std::error::Error>>;
17
 
18
/// Struct with random docs:
19
/// @relation(RUST-OUTER-LINE-DOC)
20
/// polymorphic data structure
21
pub struct Container {
22
    /// Field doc with random docs:
23
    /// @relation(RUST-OUTER-LINE-DOC)
24
    /// ethereal quantum state
25
    pub name: String,
26
 
27
    /// Another field with random docs:
28
    /// @relation(RUST-OUTER-LINE-DOC)
29
    /// cascading resonance field
30
    value: i32,
31
}
32
 
33
/// Enum with random docs:
34
/// @relation(RUST-OUTER-LINE-DOC)
35
/// enumerated variant collection
36
pub enum Status {
37
    /// Variant doc with random docs:
38
    /// @relation(RUST-OUTER-LINE-DOC)
39
    /// active processing node
40
    Active,
41
 
42
    /// Another variant with random docs:
43
    /// @relation(RUST-OUTER-LINE-DOC)
44
    /// suspended animation chamber
45
    Idle {
46
        /// Field in variant with random docs:
47
        /// @relation(RUST-OUTER-LINE-DOC)
48
        /// temporal duration metric
49
        duration: u64,
50
    },
51
 
52
    /// Tuple variant with random docs:
53
    /// @relation(RUST-OUTER-LINE-DOC)
54
    /// error state container
55
    Error(
56
        /// Tuple field with random docs:
57
        /// @relation(RUST-OUTER-LINE-DOC)
58
        /// diagnostic error code
59
        i32
60
    ),
61
}
62
 
63
/// Union with random docs:
64
/// @relation(RUST-OUTER-LINE-DOC)
65
/// memory-aligned data union
66
pub union FloatOrInt {
67
    /// Union field with random docs:
68
    /// @relation(RUST-OUTER-LINE-DOC)
69
    /// floating-point representation
70
    f: f32,
71
 
72
    /// Another union field with random docs:
73
    /// @relation(RUST-OUTER-LINE-DOC)
74
    /// integer bit pattern
75
    i: i32,
76
}
77
 
78
/// Trait definition with random docs:
79
/// @relation(RUST-OUTER-LINE-DOC)
80
/// behavioral interface contract
81
pub trait Processor {
82
    /// Associated type with random docs:
83
    /// @relation(RUST-OUTER-LINE-DOC)
84
    /// output data type
85
    type Output;
86
 
87
    /// Associated const with random docs:
88
    /// @relation(RUST-OUTER-LINE-DOC)
89
    /// maximum buffer capacity
90
    const MAX_SIZE: usize;
91
 
92
    /// Trait method with random docs:
93
    /// @relation(RUST-OUTER-LINE-DOC)
94
    /// processing operation handler
95
    fn process(&self, input: &str) -> Self::Output;
96
 
97
    /// Default method with random docs:
98
    /// @relation(RUST-OUTER-LINE-DOC)
99
    /// validation check routine
100
    fn validate(&self) -> bool {
101
        true
102
    }
103
}
104
 
105
/// Trait alias with random docs:
106
/// @relation(RUST-OUTER-LINE-DOC)
107
/// combined trait bounds
108
pub trait ProcessorClone = Processor + Clone;
109
 
110
/// Implementation block with random docs:
111
/// @relation(RUST-OUTER-LINE-DOC)
112
/// trait implementation container
113
impl Processor for Container {
114
    /// Impl associated type with
115
    /// @relation(RUST-OUTER-LINE-DOC)
116
    /// Words: concrete output type
117
    type Output = String;
118
 
119
    /// Impl const with random docs:
120
    /// @relation(RUST-OUTER-LINE-DOC)
121
    /// size constant value
122
    const MAX_SIZE: usize = 1024;
123
 
124
    /// Impl method with random docs:
125
    /// @relation(RUST-OUTER-LINE-DOC)
126
    /// implementation of a process
127
    fn process(&self, input: &str) -> Self::Output {
128
        format!("{}: {}", self.name, input)
129
    }
130
}
131
 
132
/// Inherent impl with random docs:
133
/// @relation(RUST-OUTER-LINE-DOC)
134
/// inherent method block
135
impl Container {
136
    /// Inherent method with random docs:
137
    /// @relation(RUST-OUTER-LINE-DOC)
138
    /// constructor function pattern
139
    pub fn new(name: String) -> Self {
140
        Self { name, value: 0 }
141
    }
142
 
143
    /// Another method with random docs:
144
    /// @relation(RUST-OUTER-LINE-DOC)
145
    /// getter accessor method
146
    pub fn get_value(&self) -> i32 {
147
        self.value
148
    }
149
}
150
 
151
/// Function with random docs:
152
/// @relation(RUST-OUTER-LINE-DOC)
153
/// top-level function utility
154
pub fn process_data(input: &str) -> String {
155
    input.to_uppercase()
156
}
157
 
158
/// Async function with random docs:
159
/// @relation(RUST-OUTER-LINE-DOC)
160
/// asynchronous operation handler
161
pub async fn async_process(data: Vec<u8>) -> Result<(), std::io::Error> {
162
    Ok(())
163
}
164
 
165
/// Const function with random docs:
166
/// @relation(RUST-OUTER-LINE-DOC)
167
/// compile-time evaluable function
168
pub const fn compute_magic(x: u32) -> u32 {
169
    x * 42
170
}
171
 
172
/// Unsafe function with random docs:
173
/// @relation(RUST-OUTER-LINE-DOC)
174
/// unchecked operation wrapper
175
pub unsafe fn dangerous_operation(ptr: *mut u8) {
176
    if !ptr.is_null() {
177
        *ptr = 0;
178
    }
179
}
180
 
181
/// External crate import with random docs:
182
/// @relation(RUST-OUTER-LINE-DOC)
183
/// external dependency reference
184
extern crate std;
185
 
186
/// Module with random docs:
187
/// @relation(RUST-OUTER-LINE-DOC)
188
/// nested module container
189
pub mod submodule {
190
    //! Inner module doc with random docs:
191
    //! @relation(RUST-OUTER-LINE-DOC)
192
    //! module-level documentation
193
 
194
    /// Nested struct with random docs:
195
    /// @relation(RUST-OUTER-LINE-DOC)
196
    /// encapsulated data structure
197
    pub struct Inner {
198
        /// Field with random docs:
199
        /// @relation(RUST-OUTER-LINE-DOC)
200
        /// internal state variable
201
        data: Vec<u8>,
202
    }
203
}
204
 
205
/// Foreign function interface with random docs:
206
/// @relation(RUST-OUTER-LINE-DOC)
207
/// external C interface block
208
extern "C" {
209
    /// Foreign function with random docs:
210
    /// @relation(RUST-OUTER-LINE-DOC)
211
    /// C library function binding
212
    fn external_func(x: i32) -> i32;
213
 
214
    /// Foreign static with random docs:
215
    /// @relation(RUST-OUTER-LINE-DOC)
216
    /// global C variable reference
217
    static EXTERNAL_VAR: i32;
218
 
219
    /// Foreign type with random docs:
220
    /// @relation(RUST-OUTER-LINE-DOC)
221
    /// C type declaration
222
    type OpaqueType;
223
}
224
 
225
/// Macro invocation with random docs:
226
/// @relation(RUST-OUTER-LINE-DOC)
227
/// declarative macro call
228
macro_rules! test_macro {
229
    () => {
230
        println!("test");
231
    };
232
}
233
 
234
/// Function with match arms containing doc attributes
235
/// This function demonstrates
236
/// @relation(RUST-OUTER-LINE-DOC)
237
pub fn match_example(x: Option<i32>) -> i32 {
238
    match x {
239
        /// Match arm with random docs:
240
        /// @relation(RUST-OUTER-LINE-DOC)
241
        /// some variant pattern
242
        Some(val) => val,
243
 
244
        /// None arm with random docs:
245
        /// @relation(RUST-OUTER-LINE-DOC)
246
        /// default fallback case
247
        None => 0,
248
    }
249
}
250
 
251
/// Generic function with random docs:
252
/// @relation(RUST-OUTER-LINE-DOC)
253
/// parameterized function template
254
pub fn generic_fn<
255
    /// Type parameter with random docs:
256
    /// @relation(RUST-OUTER-LINE-DOC)
257
    /// generic type variable
258
    T: Clone,
259
 
260
    /// Const parameter with random docs:
261
    /// @relation(RUST-OUTER-LINE-DOC)
262
    /// compile-time constant value
263
    const N: usize,
264
>(
265
    input: [T; N],
266
) -> Vec<T> {
267
    input.to_vec()
268
}
269
 
270
/// Struct with generic parameters random docs:
271
/// @relation(RUST-OUTER-LINE-DOC)
272
/// generic container structure
273
pub struct GenericContainer<
274
    /// Lifetime param with random docs:
275
    /// @relation(RUST-OUTER-LINE-DOC)
276
    /// reference lifetime bound
277
    'a,
278
 
279
    /// Generic type param with random docs:
280
    /// @relation(RUST-OUTER-LINE-DOC)
281
    /// primary type parameter
282
    T,
283
> where
284
    T: 'a,
285
{
286
    /// Reference field with random docs:
287
    /// @relation(RUST-OUTER-LINE-DOC)
288
    /// borrowed data reference
289
    pub data: &'a T,
290
}
291
 
292
/// Test struct for field value attributes in expressions
293
#[cfg(any(target_os = "linux", target_os = "macos"))]
294
/// This demonstrates
295
/// @relation(RUST-OUTER-LINE-DOC)
296
pub fn struct_expression_test() {
297
    let _ = Container {
298
        /// Field value with random docs:
299
        /// @relation(RUST-OUTER-LINE-DOC)
300
        name: String::from("test"),
301
        value: 42,
302
    };
303
}
304
 
305
/// Test if we can add a docstring to an expression literal
306
fn expr_lit(x: i32) -> i32 {
307
    /// Test an expression
308
    /// @relation(RUST-OUTER-LINE-DOC)
309
    8675309;
310
    /// SURPRISING: We are documenting
311
    /// @relation(RUST-OUTER-LINE-DOC)
312
    /// the first part of the expression, not the entire expression,
313
    /// see `test_not_surprising` for how to fix this
314
    x + 2
315
}
316
 
317
fn test_not_surprising(x: i32) -> i32 {
318
    /// Test documenting the
319
    /// @relation(RUST-OUTER-LINE-DOC)
320
    (x + 2)
321
}
322
 
323
#[cfg(any(test, doc))]
324
mod tests {
325
    /// Test function with random docs:
326
    /// @relation(RUST-OUTER-LINE-DOC)
327
    /// unit test case definition
328
    #[cfg_attr(not(doc), test)]
329
    fn test_basic() {
330
        assert_eq!(2 + 2, 4);
331
    }
332
}