summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch3/ch3-not-quite-file-1.rs
blob: 292d7ab0b955b382b60af606e84b244143a2e64f (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
#![allow(unused_variables)] // <1> Relax compiler warnings while working through ideas

type File = String; // <2> Create a type alias. The compiler won't distinguish between String & File, but your source code will.

fn open(f: &mut File) -> bool {
    true // <3> let's assume for the moment that this always succeeds
}

fn close(f: &mut File) -> bool {
    true // <3>
}

#[allow(dead_code)] // <4> Relaxes a compiler warning about an unused function
fn read(f: &mut File, save_to: &mut Vec<u8>) -> ! { // <5> Using `!` as a return type indicates to the Rust compiler that this function never returns
    unimplemented!() // <6> A macro that crashes the program if it is encountered
}

fn main() {
    let mut f1 = File::from("f1.txt"); // <7> With the type declaration at line 3, `File` "inherits" all of String's methods 
    open(&mut f1);
    //read(f1 , vec![]); // <8> There's little point in calling this method
    close(&mut f1);
}