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