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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// NOTE: The comments that have [START/END ...] in them are used to identify code snippets that
// appear in the documentation.  Please be aware that changes in these blocks will affect the
// documentation on fuchsia.dev.
// You can find the usages in the documenation by running:
//  find docs -name "*.md" | xargs \
//  grep "\{% includecode .*gerrit_path=\"examples/hello_world/rust/src/main.rs\""

// [START main]
fn main() {
    println!("{}, world!", greeting());
    eprintln!("{}, world!", greeting());
}

fn greeting() -> String {
    return String::from("Hello");
}
// [END main]

// [START test_mod]
#[cfg(test)]
mod tests {
    #[fuchsia::test]
    fn it_works() {
        assert_eq!(true, true);
    }
}
// [END test_mod]

#[cfg(test)]
mod hello_tests {
    use crate::greeting;

    // [START async_test]
    #[fuchsia::test]
    async fn my_test() {
        let some_future = async { 4 };
        assert_eq!(some_future.await, 4);
    }
    // [END async_test]

    #[fuchsia::test]
    fn greeting_test() {
        let expected = String::from("Hello");
        assert_eq!(greeting(), expected)
    }
}