Skip to content

Commit ed7a30e

Browse files
committed
added from example
1 parent 4e76ff8 commit ed7a30e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

fromcomplex/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "fromcomplex"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

fromcomplex/src/main.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[derive(Debug)]
2+
struct MyUnit;
3+
4+
#[derive(Debug)]
5+
#[allow(dead_code)]
6+
enum MyOption<T> {
7+
Some(T),
8+
None,
9+
}
10+
11+
impl From<()> for MyOption<MyUnit> {
12+
fn from(_: ()) -> Self {
13+
MyOption::Some(MyUnit)
14+
}
15+
}
16+
17+
fn main() {
18+
println!("{:?}", <MyOption<MyUnit>>::from(()));
19+
let o: MyOption<MyUnit> = ().into();
20+
println!("{:?}", o);
21+
}

0 commit comments

Comments
 (0)