Skip to content

Instantly share code, notes, and snippets.

@brson
Created February 15, 2012 03:30
Show Gist options
  • Save brson/1832945 to your computer and use it in GitHub Desktop.
Save brson/1832945 to your computer and use it in GitHub Desktop.
use std;
import std::dbg::refcount;
type foo<T> = {
mutable f: option<@T>
};
fn upd<T>(&&f: foo<T>, g: fn(T)) {
{
// #error["rc=%?", refcount(option::get(f.f))];
}
alt f.f {
some(v) {
// #error["f.f=%? rc=%?", f.f, refcount(v)];
{
g(*(copy v));
}
let x = v;
// #error["f.f=%? rc=%?", f.f, refcount(v)];
}
none { }
}
}
fn main() {
let x = @{mutable f: some(@3u)};
let y = x;
#error["rc=%?", refcount(option::get(y.f))];
upd(*x) {|v|
#error["v=%? rc=%?", v, refcount(option::get(y.f))];
y.f = none;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment