Skip to content

Commit ef96e2a

Browse files
committedNov 26, 2023
Update README
1 parent c985529 commit ef96e2a

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed
 

‎README.md

+8-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ or-rs is a library that extends the syntax to allow different types to be return
55
## Usage
66
Currently, the `or_gen!` macro supports Rust's `if` and `match` statement.
77

8-
### if expression
8+
**if expression**
99
```rust
1010
#![feature(proc_macro_hygiene)] // for now, you have to add this unstable feature flag
1111

@@ -16,11 +16,11 @@ fn main() {
1616
// you have to add a type annotation **explicitly** for `x`.
1717
#[or_gen]
1818
let x: Or3<i32, String, f32> = if true {
19-
3
19+
3 // this branch returns `i32`
2020
} else if false {
21-
"hello".to_string()
21+
"hello".to_string() // this branch returns `String`
2222
} else {
23-
3.0
23+
3.0 // this branch returns `f32`
2424
};
2525

2626
// Check if `x` is of type t2(=String)
@@ -32,7 +32,7 @@ fn main() {
3232
}
3333
```
3434

35-
### match expression
35+
**match expression**
3636
```rust
3737
#![feature(proc_macro_hygiene)] // for now, you have to add this unstable feature flag
3838

@@ -43,9 +43,9 @@ fn main() {
4343
// you have to add a type annotation **explicitly** for `x`.
4444
#[or_gen]
4545
let x: Or3<i32, f32, String> = match 42 {
46-
1 => 22,
47-
10 => 3.2,
48-
_ => "hello".to_string(),
46+
42 => 3, // this branch returns `i32`
47+
10 => 3.2, // this branch returns `f32`
48+
_ => "hello".to_string(), // this branch returns `String`
4949
};
5050

5151
// map works **only** when the inner value of Or is i32.
@@ -67,7 +67,6 @@ let s = if true {
6767
} else if false {
6868
"tofs".to_string()
6969
} else {
70-
11;
7170
3.0 // ERROR! `if` and `else` have incompatible types.
7271
};
7372
```
@@ -84,7 +83,6 @@ let s: Or3<i32, String, f32> = if true {
8483
} else if false {
8584
"tofs".to_string()
8685
} else {
87-
11;
8886
3.0
8987
};
9088
// -> OK: This compiles!
@@ -100,7 +98,6 @@ let s: Or3<i32, String, f32> = if true {
10098
Or3::<i32, String, f32>::T2("tofs".to_string())
10199
} else {
102100
{
103-
11;
104101
Or3::<i32, String, f32>::T3(3.0)
105102
}
106103
};

0 commit comments

Comments
 (0)
Please sign in to comment.