blob: bdf9088a2eaae6d6cad2ccc6090d3db465ee0274 (
plain) (
blame)
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
|
extern crate rand; // <> Make an external crate available to our code
use rand; // <> Bring `rand` into local scope
static mut ERROR: isize = 0;
struct File;
#[allow(unused_variables)]
fn read(f: &File, save_to: Vec<u8>) -> usize {
if rand::thread_rng().gen_weighted_bool(10000) {
unsafe {
ERROR = 1;
}
}
0 // <> Always read() 0 bytes
}
#[allow(unused_mut)]
fn main() {
let mut f = File;
let mut buffer = vec![];
read(&f, buffer);
unsafe {
if ERROR != 0 {
panic!("An error has occurred!")
}
}
}
|