mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Replace the FooCast traits by structs.
This should allow us to remove most type annotations in the DOM.
This commit is contained in:
parent
c54e79b2f2
commit
0e11178d66
1 changed files with 11 additions and 11 deletions
|
@ -5254,9 +5254,10 @@ impl ${selfName} for ${baseName} {
|
||||||
derived += [CGGeneric('\n')]
|
derived += [CGGeneric('\n')]
|
||||||
|
|
||||||
cast = [CGGeneric(string.Template("""\
|
cast = [CGGeneric(string.Template("""\
|
||||||
pub trait ${castTraitName} : Sized {
|
pub struct ${name}Cast;
|
||||||
|
impl ${name}Cast {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_ref<'a, T: ${toBound}+Reflectable>(base: JSRef<'a, T>) -> Option<JSRef<'a, Self>> {
|
pub fn to_ref<'a, T: ${toBound}+Reflectable>(base: JSRef<'a, T>) -> Option<JSRef<'a, ${name}>> {
|
||||||
match base.${checkFn}() {
|
match base.${checkFn}() {
|
||||||
true => unsafe { Some(base.transmute()) },
|
true => unsafe { Some(base.transmute()) },
|
||||||
false => None
|
false => None
|
||||||
|
@ -5264,7 +5265,7 @@ pub trait ${castTraitName} : Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_borrowed_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, Self>> {
|
pub fn to_borrowed_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, ${name}>> {
|
||||||
match base.${checkFn}() {
|
match base.${checkFn}() {
|
||||||
true => unsafe { Some(base.transmute_borrowed()) },
|
true => unsafe { Some(base.transmute_borrowed()) },
|
||||||
false => None
|
false => None
|
||||||
|
@ -5273,7 +5274,7 @@ pub trait ${castTraitName} : Sized {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<Self>> {
|
pub fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<${name}>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
match (*base.unsafe_get()).${checkFn}() {
|
match (*base.unsafe_get()).${checkFn}() {
|
||||||
true => Some(base.transmute_copy()),
|
true => Some(base.transmute_copy()),
|
||||||
|
@ -5283,30 +5284,29 @@ pub trait ${castTraitName} : Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: JSRef<'a, T>) -> JSRef<'a, Self> {
|
pub fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: JSRef<'a, T>) -> JSRef<'a, ${name}> {
|
||||||
unsafe { derived.transmute() }
|
unsafe { derived.transmute() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from_borrowed_ref<'a, 'b, T: ${fromBound}+Reflectable>(derived: &'a JSRef<'b, T>) -> &'a JSRef<'b, Self> {
|
pub fn from_borrowed_ref<'a, 'b, T: ${fromBound}+Reflectable>(derived: &'a JSRef<'b, T>) -> &'a JSRef<'b, ${name}> {
|
||||||
unsafe { derived.transmute_borrowed() }
|
unsafe { derived.transmute_borrowed() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from_temporary<T: ${fromBound}+Reflectable>(derived: Temporary<T>) -> Temporary<Self> {
|
pub fn from_temporary<T: ${fromBound}+Reflectable>(derived: Temporary<T>) -> Temporary<${name}> {
|
||||||
unsafe { derived.transmute() }
|
unsafe { derived.transmute() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from_actual<'a, T: ${fromBound}+Reflectable>(derived: &T) -> &'a Self {
|
pub fn from_actual<'a, T: ${fromBound}+Reflectable>(derived: &T) -> &'a ${name} {
|
||||||
unsafe { mem::transmute(derived) }
|
unsafe { mem::transmute(derived) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""").substitute({'checkFn': 'is_' + name.lower(),
|
""").substitute({'checkFn': 'is_' + name.lower(),
|
||||||
'castTraitName': name + 'Cast',
|
'name': name,
|
||||||
'fromBound': name + 'Base',
|
'fromBound': name + 'Base',
|
||||||
'toBound': name + 'Derived'})),
|
'toBound': name + 'Derived'}))]
|
||||||
CGGeneric("impl %s for %s {}\n\n" % (name + 'Cast', name))]
|
|
||||||
|
|
||||||
allprotos += protos + derived + cast
|
allprotos += protos + derived + cast
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue