1
- mod ticket {
1
+ /// We will begin our journey of building our own JIRA clone defining the cornerstone of
2
+ /// JIRA's experience: the ticket.
3
+ /// For now we want to limit ourselves to the essentials: each ticket will have a title
4
+ /// and a description.
5
+ /// No, not an ID yet. We will get to that in due time.
6
+ ///
7
+ /// There are various ways to represent a set of related pieces of information in Rust.
8
+ /// We'll go for a `struct`: a struct is quite similar to what you would call a class or
9
+ /// an object in object-oriented programming languages.
10
+ /// It is a collection of fields, each one with its own name.
11
+ /// Given that Rust is a strongly-typed language, we also need to specify a type for each
12
+ /// of those fields.
13
+ ///
14
+ /// Our definition of Ticket is incomplete - can you replace __ with what is missing to make
15
+ /// this snippet compile and the tests below succeed?
16
+ ///
17
+ /// You can find more about structs in the Rust Book: https://doc.rust-lang.org/book/ch05-01-defining-structs.html
18
+ pub struct Ticket {
19
+ title : String ,
20
+ __ : __
21
+ }
2
22
3
- /// We will begin our journey of building our own JIRA clone defining the cornerstone of
4
- /// JIRA's experience: the ticket.
5
- /// For now we want to limit ourselves to the essentials: each ticket will have a title
6
- /// and a description.
7
- /// No, not an ID yet. We will get to that in due time.
8
- ///
9
- /// There are various ways to represent a set of related pieces of information in Rust.
10
- /// We'll go for a `struct`: a struct is quite similar to what you would call a class or
11
- /// an object in object-oriented programming languages.
12
- /// It is a collection of fields, each one with its own name.
13
- /// Given that Rust is a strongly-typed language, we also need to specify a type for each
14
- /// of those fields.
15
- ///
16
- /// Our definition of Ticket is incomplete - can you replace __ with what is missing to make
17
- /// this snippet compile and the tests below succeed?
18
- ///
19
- /// You can find more about structs in the Rust Book: https://doc.rust-lang.org/book/ch05-01-defining-structs.html
20
- pub struct Ticket {
21
- title : String ,
22
- __
23
- }
23
+ /// `cfg` stands for configuration flag.
24
+ /// The #[cfg(_)] attribute is used to mark a section of the code for conditional compilation
25
+ /// based on the value of the specified flag.
26
+ /// #[cfg(test)] is used to mark sections of our codebase that should only be compiled
27
+ /// when running `cargo test`...
28
+ /// Yes, tests!
29
+ ///
30
+ /// You can put tests in different places in a Rust project, depending on what you are
31
+ /// trying to do: unit testing of private functions and methods, testing an internal API,
32
+ /// integration testing your crate from the outside, etc.
33
+ /// You can find more details on test organisation in the Rust book:
34
+ /// https://doc.rust-lang.org/book/ch11-03-test-organization.html
35
+ ///
36
+ /// Let it be said that tests are first-class citizens in the Rust ecosystem and you are
37
+ /// provided with a barebone test framework out of the box.
38
+ #[ cfg( test) ]
39
+ mod tests {
40
+ use super :: * ;
24
41
25
- /// `cfg` stands for configuration flag.
26
- /// The #[cfg(_)] attribute is used to mark a section of the code for conditional compilation
27
- /// based on the value of the specified flag.
28
- /// #[cfg(test)] is used to mark sections of our codebase that should only be compiled
29
- /// when running `cargo test`...
30
- /// Yes, tests!
31
- ///
32
- /// You can put tests in different places in a Rust project, depending on what you are
33
- /// trying to do: unit testing of private functions and methods, testing an internal API,
34
- /// integration testing your crate from the outside, etc.
35
- /// You can find more details on test organisation in the Rust book:
36
- /// https://doc.rust-lang.org/book/ch11-03-test-organization.html
42
+ /// The #[test] attribute is used to mark a function as a test for the compiler.
43
+ /// Tests take no arguments: when we run `cargo test`, this function will be invoked.
44
+ /// If it runs without raising any issue, the test is considered green - it passed.
45
+ /// If it panics (raises a fatal exception), then the test is considered red - it failed.
37
46
///
38
- /// Let it be said that tests are first-class citizens in the Rust ecosystem and you are
39
- /// provided with a barebone test framework out of the box.
40
- #[ cfg( test) ]
41
- mod tests {
42
- use super :: * ;
43
-
44
- /// The #[test] attribute is used to mark a function as a test for the compiler.
45
- /// Tests take no arguments: when we run `cargo test`, this function will be invoked.
46
- /// If it runs without raising any issue, the test is considered green - it passed.
47
- /// If it panics (raises a fatal exception), then the test is considered red - it failed.
47
+ /// `cargo test` reports on the number of failed tests at the end of each run, with some
48
+ /// associated diagnostics to make it easier to understand what went wrong exactly.
49
+ #[ test]
50
+ fn your_first_ticket ( ) {
51
+ /// `let` is used to create a variable: we are binding a new `Ticket` struct
52
+ /// to the name `ticket_one`.
48
53
///
49
- /// `cargo test` reports on the number of failed tests at the end of each run, with some
50
- /// associated diagnostics to make it easier to understand what went wrong exactly.
51
- #[ test]
52
- fn your_first_ticket ( ) {
53
- /// `let` is used to create a variable: we are binding a new `Ticket` struct
54
- /// to the name `ticket_one`.
55
- ///
56
- /// We said before that Rust is strongly typed, nonetheless we haven't specified
57
- /// a type for `ticket_one`.
58
- /// As most modern strongly typed programming languages, Rust provides type inference:
59
- /// the compiler is smart enough to figure out the type of variables based on
60
- /// their usage and it won't bother you unless the type is ambiguous.
61
- let ticket_one = Ticket {
62
- /// This `.into()` method call is here for a reason, but give us time.
63
- /// We'll get there when it's the right moment.
64
- title : "A ticket title" . into ( ) ,
65
- description : "A heart-breaking description" . into ( )
66
- } ;
54
+ /// We said before that Rust is strongly typed, nonetheless we haven't specified
55
+ /// a type for `ticket_one`.
56
+ /// As most modern strongly typed programming languages, Rust provides type inference:
57
+ /// the compiler is smart enough to figure out the type of variables based on
58
+ /// their usage and it won't bother you unless the type is ambiguous.
59
+ let ticket_one = Ticket {
60
+ /// This `.into()` method call is here for a reason, but give us time.
61
+ /// We'll get there when it's the right moment.
62
+ title : "A ticket title" . into ( ) ,
63
+ description : "A heart-breaking description" . into ( )
64
+ } ;
67
65
68
- /// `assert_eq` is a macro (notice the ! at the end of the name).
69
- /// It checks that the left argument (the expected value) is identical
70
- /// to the right argument (the computed value).
71
- /// If they are not, it panics - Rust's (almost) non-recoverable way to terminate a program.
72
- /// In the case of tests, this is caught by the test framework and the test is marked as failed.
73
- assert_eq ! ( ticket_one. title, "A ticket title" ) ;
74
- /// Field syntax: you use a dot to access the field of a struct.
75
- assert_eq ! ( ticket_one. description, "A heart-breaking description" ) ;
76
- }
66
+ /// `assert_eq` is a macro (notice the ! at the end of the name).
67
+ /// It checks that the left argument (the expected value) is identical
68
+ /// to the right argument (the computed value).
69
+ /// If they are not, it panics - Rust's (almost) non-recoverable way to terminate a program.
70
+ /// In the case of tests, this is caught by the test framework and the test is marked as failed.
71
+ assert_eq ! ( ticket_one. title, "A ticket title" ) ;
72
+ /// Field syntax: you use a dot to access the field of a struct.
73
+ assert_eq ! ( ticket_one. description, "A heart-breaking description" ) ;
77
74
}
78
- }
75
+ }
0 commit comments