2016-04-22 07:38:46 -05:00
|
|
|
#[derive(Debug, PartialEq)]
|
2022-06-22 00:57:06 -05:00
|
|
|
enum Unit {
|
|
|
|
Unit(()),
|
|
|
|
} // Force non-C-enum representation.
|
2016-03-13 07:05:48 -05:00
|
|
|
|
|
|
|
fn return_unit() -> Unit {
|
2016-04-23 01:03:59 -05:00
|
|
|
Unit::Unit(())
|
2016-03-13 07:05:48 -05:00
|
|
|
}
|
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
#[derive(Debug, PartialEq)]
|
2022-06-22 00:57:06 -05:00
|
|
|
enum MyBool {
|
|
|
|
False(()),
|
|
|
|
True(()),
|
|
|
|
} // Force non-C-enum representation.
|
2016-03-13 07:05:48 -05:00
|
|
|
|
|
|
|
fn return_true() -> MyBool {
|
2016-04-23 01:03:59 -05:00
|
|
|
MyBool::True(())
|
2016-03-13 07:05:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn return_false() -> MyBool {
|
2016-04-23 01:03:59 -05:00
|
|
|
MyBool::False(())
|
2016-03-13 07:05:48 -05:00
|
|
|
}
|
|
|
|
|
2016-03-12 22:27:54 -06:00
|
|
|
fn return_none() -> Option<i64> {
|
|
|
|
None
|
|
|
|
}
|
2016-03-12 21:32:24 -06:00
|
|
|
|
2016-03-12 22:27:54 -06:00
|
|
|
fn return_some() -> Option<i64> {
|
|
|
|
Some(42)
|
|
|
|
}
|
|
|
|
|
2016-03-13 07:30:28 -05:00
|
|
|
fn match_opt_none() -> i8 {
|
2016-03-13 08:23:48 -05:00
|
|
|
let x = None;
|
2016-03-13 07:30:28 -05:00
|
|
|
match x {
|
2016-03-13 08:23:48 -05:00
|
|
|
Some(data) => data,
|
|
|
|
None => 42,
|
2016-03-13 07:30:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn match_opt_some() -> i8 {
|
|
|
|
let x = Some(13);
|
|
|
|
match x {
|
2016-03-13 08:23:48 -05:00
|
|
|
Some(data) => data,
|
2016-03-13 07:30:28 -05:00
|
|
|
None => 20,
|
|
|
|
}
|
|
|
|
}
|
2016-04-06 05:08:52 -05:00
|
|
|
|
|
|
|
fn two_nones() -> (Option<i16>, Option<i16>) {
|
|
|
|
(None, None)
|
|
|
|
}
|
2016-04-22 03:34:14 -05:00
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
fn main() {
|
2016-05-10 00:41:57 -05:00
|
|
|
assert_eq!(two_nones(), (None, None));
|
2016-04-22 07:38:46 -05:00
|
|
|
assert_eq!(match_opt_some(), 13);
|
|
|
|
assert_eq!(match_opt_none(), 42);
|
2016-05-10 00:41:57 -05:00
|
|
|
assert_eq!(return_some(), Some(42));
|
|
|
|
assert_eq!(return_none(), None);
|
|
|
|
assert_eq!(return_false(), MyBool::False(()));
|
|
|
|
assert_eq!(return_true(), MyBool::True(()));
|
|
|
|
assert_eq!(return_unit(), Unit::Unit(()));
|
2016-04-22 07:38:46 -05:00
|
|
|
}
|