mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
auto merge of #1947 : saneyuki/servo/cast, r=jdm
follow up https://github.com/mozilla/servo/pull/1864#issuecomment-37109672
This commit is contained in:
commit
e67d8a4003
1 changed files with 3 additions and 0 deletions
|
@ -5745,10 +5745,12 @@ class GlobalGenRoots():
|
|||
derived += [CGGeneric('\n')]
|
||||
|
||||
cast = [CGGeneric(string.Template('''pub trait ${castTraitName} {
|
||||
#[inline(always)]
|
||||
fn from<T: ${fromBound}>(derived: &JS<T>) -> JS<Self> {
|
||||
unsafe { derived.clone().transmute() }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn to<T: ${toBound}>(base: &JS<T>) -> Option<JS<Self>> {
|
||||
match base.get().${checkFn}() {
|
||||
true => unsafe { Some(base.clone().transmute()) },
|
||||
|
@ -5756,6 +5758,7 @@ class GlobalGenRoots():
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn to_unchecked<T: ${toBound}>(base: &JS<T>) -> JS<Self> {
|
||||
assert!(base.get().${checkFn}());
|
||||
base.clone().transmute()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue