Make option::get return the option contents by reference

I can't believe this actually works!
This commit is contained in:
Marijn Haverbeke 2011-09-15 17:47:39 +02:00
parent 906f1fc425
commit fc0bf12516

View file

@ -2,8 +2,8 @@
tag t<@T> { none; some(T); }
fn get<@T>(opt: t<T>) -> T {
alt opt { some(x) { x } none. { fail "option none" } }
fn get<@T>(opt: t<T>) -> &T {
alt opt { some(x) { ret x; } none. { fail "option none"; } }
}
fn map<@T, @U>(f: block(T) -> U, opt: t<T>) -> t<U> {