[librsvg: 1/2] Remove the generic type argument from trait Property
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/2] Remove the generic type argument from trait Property
- Date: Tue, 3 Aug 2021 20:06:29 +0000 (UTC)
commit 4a6c9ed1dea327b06c94050537fc3e0bd1aaddf4
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Jul 28 18:04:24 2021 -0500
Remove the generic type argument from trait Property
It's always used as Property<ComputedValues>, so let's hardcode that
instead.
Originally, the reason for Property<T> was to be able to write a mock
T for the Property trait's initial tests - but those tests are long
gone anyway.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/574>
src/properties.rs | 13 +++++--------
src/property_defs.rs | 8 ++++----
src/property_macros.rs | 24 +++++++++++++-----------
3 files changed, 22 insertions(+), 23 deletions(-)
---
diff --git a/src/properties.rs b/src/properties.rs
index 9502d32d..c2d59998 100644
--- a/src/properties.rs
+++ b/src/properties.rs
@@ -45,7 +45,7 @@ pub use crate::property_defs::*;
#[derive(Clone)]
pub enum SpecifiedValue<T>
where
- T: Property<ComputedValues> + Clone + Default,
+ T: Property + Clone + Default,
{
Unspecified,
Inherit,
@@ -54,12 +54,12 @@ where
impl<T> SpecifiedValue<T>
where
- T: Property<ComputedValues> + Clone + Default,
+ T: Property + Clone + Default,
{
pub fn compute(&self, src: &T, src_values: &ComputedValues) -> T {
let value: T = match *self {
SpecifiedValue::Unspecified => {
- if <T as Property<ComputedValues>>::inherits_automatically() {
+ if <T as Property>::inherits_automatically() {
src.clone()
} else {
Default::default()
@@ -796,7 +796,7 @@ impl SpecifiedValues {
// Parses the value for the type `T` of the property out of the Parser, including `inherit` values.
fn parse_input<'i, T>(input: &mut Parser<'i, '_>) -> Result<SpecifiedValue<T>, ParseError<'i>>
where
- T: Property<ComputedValues> + Clone + Default + Parse,
+ T: Property + Clone + Default + Parse,
{
if input
.try_parse(|p| p.expect_ident_matching("inherit"))
@@ -898,10 +898,7 @@ mod tests {
#[test]
fn computes_property_that_does_not_inherit_automatically() {
- assert_eq!(
- <Opacity as Property<ComputedValues>>::inherits_automatically(),
- false
- );
+ assert_eq!(<Opacity as Property>::inherits_automatically(), false);
let half_opacity = Opacity::parse_str("0.5").unwrap();
diff --git a/src/property_defs.rs b/src/property_defs.rs
index f0832101..05b667a5 100644
--- a/src/property_defs.rs
+++ b/src/property_defs.rs
@@ -61,7 +61,7 @@ make_property!(
default: Length::<Both>::parse_str("0.0").unwrap(),
newtype: Length<Both>,
property_impl: {
- impl Property<ComputedValues> for BaselineShift {
+ impl Property for BaselineShift {
fn inherits_automatically() -> bool {
false
}
@@ -408,7 +408,7 @@ make_property!(
FontSize,
default: FontSize::Value(Length::<Both>::parse_str("12.0").unwrap()),
property_impl: {
- impl Property<ComputedValues> for FontSize {
+ impl Property for FontSize {
fn inherits_automatically() -> bool {
true
}
@@ -482,7 +482,7 @@ make_property!(
FontWeight,
default: FontWeight::Normal,
property_impl: {
- impl Property<ComputedValues> for FontWeight {
+ impl Property for FontWeight {
fn inherits_automatically() -> bool {
true
}
@@ -499,7 +499,7 @@ make_property!(
LetterSpacing,
default: LetterSpacing::Normal,
property_impl: {
- impl Property<ComputedValues> for LetterSpacing {
+ impl Property for LetterSpacing {
fn inherits_automatically() -> bool {
true
}
diff --git a/src/property_macros.rs b/src/property_macros.rs
index 8c997e14..bb3fea85 100644
--- a/src/property_macros.rs
+++ b/src/property_macros.rs
@@ -1,10 +1,12 @@
//! Macros to define CSS properties.
+use crate::properties::ComputedValues;
+
/// Trait which all CSS property types should implement.
///
/// This is generic on `T` for testing purposes; in the actual code `T` needs to
/// be [`ComputedValues`][crate::properties::ComputedValues].
-pub trait Property<T> {
+pub trait Property {
/// Whether the property's computed value inherits from parent to child elements.
///
/// For each property, the CSS or SVG specs say whether the property inherits
@@ -18,7 +20,7 @@ pub trait Property<T> {
/// `self` value.
///
/// The CSS or SVG specs say how to derive this for each property.
- fn compute(&self, _: &T) -> Self;
+ fn compute(&self, _: &ComputedValues) -> Self;
}
/// Generates a type for a CSS property.
@@ -120,7 +122,7 @@ macro_rules! make_property {
}
impl_default!($name, $name::$default);
- impl_property!(crate::properties::ComputedValues, $name, $inherits_automatically);
+ impl_property!($name, $inherits_automatically);
impl crate::parsers::Parse for $name {
fn parse<'i>(parser: &mut ::cssparser::Parser<'i, '_>) -> Result<$name,
crate::error::ParseError<'i>> {
@@ -143,7 +145,7 @@ macro_rules! make_property {
pub struct $name(pub $type);
impl_default!($name, $name($default));
- impl_property!(crate::properties::ComputedValues, $name, $inherits_automatically);
+ impl_property!($name, $inherits_automatically);
impl crate::parsers::Parse for $name {
fn parse<'i>(parser: &mut ::cssparser::Parser<'i, '_>) -> Result<$name,
crate::error::ParseError<'i>> {
@@ -167,7 +169,7 @@ macro_rules! make_property {
inherits_automatically: $inherits_automatically: expr,
) => {
impl_default!($name, $default);
- impl_property!(crate::properties::ComputedValues, $name, $inherits_automatically);
+ impl_property!($name, $inherits_automatically);
};
($name: ident,
@@ -176,7 +178,7 @@ macro_rules! make_property {
parse_impl: { $parse: item }
) => {
impl_default!($name, $default);
- impl_property!(crate::properties::ComputedValues, $name, $inherits_automatically);
+ impl_property!($name, $inherits_automatically);
$parse
};
@@ -213,7 +215,7 @@ macro_rules! make_property {
pub struct $name(pub $type);
impl_default!($name, $name($default));
- impl_property!(crate::properties::ComputedValues, $name, $inherits_automatically);
+ impl_property!($name, $inherits_automatically);
$parse
};
@@ -233,7 +235,7 @@ macro_rules! make_property {
}
impl_default!($name, $name { $($field_name: $field_default),+ });
- impl_property!(crate::properties::ComputedValues, $name, $inherits_automatically);
+ impl_property!($name, $inherits_automatically);
$parse
};
@@ -250,13 +252,13 @@ macro_rules! impl_default {
}
macro_rules! impl_property {
- ($computed_values_type:ty, $name:ident, $inherits_automatically:expr) => {
- impl crate::property_macros::Property<$computed_values_type> for $name {
+ ($name:ident, $inherits_automatically:expr) => {
+ impl crate::property_macros::Property for $name {
fn inherits_automatically() -> bool {
$inherits_automatically
}
- fn compute(&self, _v: &$computed_values_type) -> Self {
+ fn compute(&self, _v: &crate::properties::ComputedValues) -> Self {
self.clone()
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]