mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
style: Remove HasFFI as well
After the previous patches we only have one trait which we should also tweak / rework, so let's put it all on that single trait. Differential Revision: https://phabricator.services.mozilla.com/D177515
This commit is contained in:
parent
42cbb9d3cf
commit
e18675401e
2 changed files with 13 additions and 24 deletions
|
@ -17,7 +17,7 @@ use crate::gecko_bindings::structs::{
|
|||
RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule,
|
||||
RawServoStyleSheetContents, RawServoSupportsRule, ServoCssRules,
|
||||
};
|
||||
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong};
|
||||
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, Strong};
|
||||
use crate::media_queries::MediaList;
|
||||
use crate::properties::animated_properties::AnimationValue;
|
||||
use crate::properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
|
@ -33,10 +33,9 @@ use std::{mem, ptr};
|
|||
|
||||
macro_rules! impl_arc_ffi {
|
||||
($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => {
|
||||
unsafe impl HasFFI for $servo_type {
|
||||
unsafe impl HasArcFFI for $servo_type {
|
||||
type FFIType = $gecko_type;
|
||||
}
|
||||
unsafe impl HasArcFFI for $servo_type {}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn $addref(obj: &$gecko_type) {
|
||||
|
|
|
@ -11,21 +11,18 @@ use std::mem::{forget, transmute};
|
|||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
|
||||
/// Indicates that a given Servo type has a corresponding Gecko FFI type.
|
||||
pub unsafe trait HasFFI: Sized + 'static {
|
||||
/// The corresponding Gecko type that this rust type represents.
|
||||
///
|
||||
/// See the examples in `components/style/gecko/conversions.rs`.
|
||||
type FFIType: Sized;
|
||||
}
|
||||
|
||||
/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs
|
||||
///
|
||||
/// Should be implemented by types which are passed over FFI as Arcs via Strong
|
||||
/// and Borrowed.
|
||||
///
|
||||
/// In this case, the FFIType is the rough equivalent of ArcInner<Self>.
|
||||
pub unsafe trait HasArcFFI: HasFFI {
|
||||
pub unsafe trait HasArcFFI: Sized + 'static {
|
||||
/// The corresponding Gecko type that this rust type represents.
|
||||
///
|
||||
/// See the examples in `components/style/gecko/conversions.rs`.
|
||||
type FFIType: Sized;
|
||||
|
||||
// these methods can't be on Borrowed because it leads to an unspecified
|
||||
// impl parameter
|
||||
/// Artificially increments the refcount of a (possibly null) borrowed Arc
|
||||
|
@ -163,26 +160,21 @@ impl<GeckoType> Strong<GeckoType> {
|
|||
|
||||
/// A few helpers implemented on top of Arc<ServoType> to make it more
|
||||
/// comfortable to use and write safe code with.
|
||||
pub unsafe trait FFIArcHelpers {
|
||||
/// The Rust FFI type that we're implementing methods for.
|
||||
type Inner: HasArcFFI;
|
||||
|
||||
pub unsafe trait FFIArcHelpers<T: HasArcFFI> {
|
||||
/// Converts an Arc into a strong FFI reference.
|
||||
///
|
||||
/// Arc<ServoType> -> Strong<GeckoType>
|
||||
fn into_strong(self) -> Strong<<Self::Inner as HasFFI>::FFIType>;
|
||||
fn into_strong(self) -> Strong<T::FFIType>;
|
||||
|
||||
/// Produces a borrowed FFI reference by borrowing an Arc.
|
||||
///
|
||||
/// &Arc<ServoType> -> &GeckoType
|
||||
///
|
||||
/// Then the `arc_as_borrowed` method can go away.
|
||||
fn as_borrowed(&self) -> &<Self::Inner as HasFFI>::FFIType;
|
||||
fn as_borrowed(&self) -> &T::FFIType;
|
||||
}
|
||||
|
||||
unsafe impl<T: HasArcFFI> FFIArcHelpers for RawOffsetArc<T> {
|
||||
type Inner = T;
|
||||
|
||||
unsafe impl<T: HasArcFFI> FFIArcHelpers<T> for RawOffsetArc<T> {
|
||||
#[inline]
|
||||
fn into_strong(self) -> Strong<T::FFIType> {
|
||||
unsafe { transmute(self) }
|
||||
|
@ -194,9 +186,7 @@ unsafe impl<T: HasArcFFI> FFIArcHelpers for RawOffsetArc<T> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: HasArcFFI> FFIArcHelpers for Arc<T> {
|
||||
type Inner = T;
|
||||
|
||||
unsafe impl<T: HasArcFFI> FFIArcHelpers<T> for Arc<T> {
|
||||
#[inline]
|
||||
fn into_strong(self) -> Strong<T::FFIType> {
|
||||
Arc::into_raw_offset(self).into_strong()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue