Split TCast::to into TCast::to_unchecked and TCast::to.

This commit is contained in:
Tetsuharu OHZEKI 2014-03-09 00:14:14 +09:00
parent 19a7c429a1
commit 0fccf5e386
10 changed files with 71 additions and 64 deletions

View file

@ -5791,9 +5791,16 @@ class GlobalGenRoots():
unsafe { derived.clone().transmute() }
}
fn to<T: ${toBound}>(base: &JS<T>) -> JS<Self> {
fn to<T: ${toBound}>(base: &JS<T>) -> Option<JS<Self>> {
match base.get().${checkFn}() {
true => unsafe { Some(base.clone().transmute()) },
false => None
}
}
unsafe fn to_unchecked<T: ${toBound}>(base: &JS<T>) -> JS<Self> {
assert!(base.get().${checkFn}());
unsafe { base.clone().transmute() }
base.clone().transmute()
}
}
''').substitute({'checkFn': 'is_' + name.lower(),