Skip to content

Instantly share code, notes, and snippets.

@abiriadev
Last active December 7, 2021 13:05
Show Gist options
  • Save abiriadev/8662f5e2eab184ea1858ec449fc906de to your computer and use it in GitHub Desktop.
Save abiriadev/8662f5e2eab184ea1858ec449fc906de to your computer and use it in GitHub Desktop.
lol
fn main() -> Result<(
)
, Box<
dyn std
::error
::Error
>
> {
let number1:
i32 = 1;
let number2:
u8 = 2;
if let Option
::Some(
res
) = add_two(
number1,
number2,
) as Option<i64> {
println!("{}", res);
}
Ok(())
}
fn add_two<T: std
::convert
::Into<V>
, V: std
::ops
::Add<
Output = V
>
, U
>(
a: T,
b: U,
) -> Option<V> where
U: std
::convert
::Into<V>
,
{
enum E<
T,
V,
> {
A(T),
B(V),
}
[ E::A(a)
, E::B(b)
]
.map(
| val |
match val {
E::A(a) => a.into(),
E::B(b) => b.into(),
}
)
.into_iter()
.reduce(
| s, a |
s + a
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment