mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Use 2018-style paths in code generated by style_derive
This commit is contained in:
parent
b60006ae11
commit
ede79a6a5d
9 changed files with 65 additions and 65 deletions
|
@ -16,7 +16,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
if !no_bound.contains(¶m.ident) {
|
if !no_bound.contains(¶m.ident) {
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(#param: ::values::animated::Animate),
|
parse_quote!(#param: crate::values::animated::Animate),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,13 +51,13 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::values::animated::Animate for #name #ty_generics #where_clause {
|
impl #impl_generics crate::values::animated::Animate for #name #ty_generics #where_clause {
|
||||||
#[allow(unused_variables, unused_imports)]
|
#[allow(unused_variables, unused_imports)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn animate(
|
fn animate(
|
||||||
&self,
|
&self,
|
||||||
other: &Self,
|
other: &Self,
|
||||||
procedure: ::values::animated::Procedure,
|
procedure: crate::values::animated::Procedure,
|
||||||
) -> Result<Self, ()> {
|
) -> Result<Self, ()> {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
#match_body
|
#match_body
|
||||||
|
@ -84,12 +84,12 @@ fn derive_variant_arm(variant: &VariantInfo) -> Result<Tokens, ()> {
|
||||||
if #this != #other {
|
if #this != #other {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
let #result = ::std::clone::Clone::clone(#this);
|
let #result = std::clone::Clone::clone(#this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
let #result =
|
let #result =
|
||||||
::values::animated::Animate::animate(#this, #other, procedure)?;
|
crate::values::animated::Animate::animate(#this, #other, procedure)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub fn fmap_trait_output(input: &DeriveInput, trait_path: &Path, trait_output: I
|
||||||
&GenericParam::Type(ref data) => {
|
&GenericParam::Type(ref data) => {
|
||||||
let ident = data.ident;
|
let ident = data.ident;
|
||||||
GenericArgument::Type(
|
GenericArgument::Type(
|
||||||
parse_quote!(<#ident as ::#trait_path>::#trait_output),
|
parse_quote!(<#ident as #trait_path>::#trait_output),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
ref arg => panic!("arguments {:?} cannot be mapped yet", arg),
|
ref arg => panic!("arguments {:?} cannot be mapped yet", arg),
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
if !no_bound.contains(¶m.ident) {
|
if !no_bound.contains(¶m.ident) {
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(#param: ::values::distance::ComputeSquaredDistance),
|
parse_quote!(#param: crate::values::distance::ComputeSquaredDistance),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
let (this_pattern, this_info) = cg::ref_pattern(&variant, "this");
|
let (this_pattern, this_info) = cg::ref_pattern(&variant, "this");
|
||||||
let (other_pattern, other_info) = cg::ref_pattern(&variant, "other");
|
let (other_pattern, other_info) = cg::ref_pattern(&variant, "other");
|
||||||
let sum = if this_info.is_empty() {
|
let sum = if this_info.is_empty() {
|
||||||
quote! { ::values::distance::SquaredDistance::from_sqrt(0.) }
|
quote! { crate::values::distance::SquaredDistance::from_sqrt(0.) }
|
||||||
} else {
|
} else {
|
||||||
let mut sum = quote!();
|
let mut sum = quote!();
|
||||||
sum.append_separated(this_info.iter().zip(&other_info).map(|(this, other)| {
|
sum.append_separated(this_info.iter().zip(&other_info).map(|(this, other)| {
|
||||||
|
@ -44,7 +44,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
let ty = &this.ast().ty;
|
let ty = &this.ast().ty;
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(#ty: ::values::distance::ComputeSquaredDistance),
|
parse_quote!(#ty: crate::values::distance::ComputeSquaredDistance),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
if #this != #other {
|
if #this != #other {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
::values::distance::SquaredDistance::from_sqrt(0.)
|
crate::values::distance::SquaredDistance::from_sqrt(0.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
::values::distance::ComputeSquaredDistance::compute_squared_distance(#this, #other)?
|
crate::values::distance::ComputeSquaredDistance::compute_squared_distance(#this, #other)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}), quote!(+));
|
}), quote!(+));
|
||||||
|
@ -95,13 +95,13 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::values::distance::ComputeSquaredDistance for #name #ty_generics #where_clause {
|
impl #impl_generics crate::values::distance::ComputeSquaredDistance for #name #ty_generics #where_clause {
|
||||||
#[allow(unused_variables, unused_imports)]
|
#[allow(unused_variables, unused_imports)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_squared_distance(
|
fn compute_squared_distance(
|
||||||
&self,
|
&self,
|
||||||
other: &Self,
|
other: &Self,
|
||||||
) -> Result<::values::distance::SquaredDistance, ()> {
|
) -> Result<crate::values::distance::SquaredDistance, ()> {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
#match_body
|
#match_body
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
||||||
match_ignore_ascii_case! { &ident,
|
match_ignore_ascii_case! { &ident,
|
||||||
#match_body
|
#match_body
|
||||||
_ => Err(location.new_unexpected_token_error(
|
_ => Err(location.new_unexpected_token_error(
|
||||||
::cssparser::Token::Ident(ident.clone())
|
cssparser::Token::Ident(ident.clone())
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,12 +88,12 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
||||||
};
|
};
|
||||||
|
|
||||||
let parse_trait_impl = quote! {
|
let parse_trait_impl = quote! {
|
||||||
impl ::parser::Parse for #name {
|
impl crate::parser::Parse for #name {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
#context_ident: &::parser::ParserContext,
|
#context_ident: &crate::parser::ParserContext,
|
||||||
input: &mut ::cssparser::Parser<'i, 't>,
|
input: &mut cssparser::Parser<'i, 't>,
|
||||||
) -> Result<Self, ::style_traits::ParseError<'i>> {
|
) -> Result<Self, style_traits::ParseError<'i>> {
|
||||||
#parse_body
|
#parse_body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,13 +110,13 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
||||||
/// Parse this keyword.
|
/// Parse this keyword.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parse<'i, 't>(
|
pub fn parse<'i, 't>(
|
||||||
input: &mut ::cssparser::Parser<'i, 't>,
|
input: &mut cssparser::Parser<'i, 't>,
|
||||||
) -> Result<Self, ::style_traits::ParseError<'i>> {
|
) -> Result<Self, style_traits::ParseError<'i>> {
|
||||||
let location = input.current_source_location();
|
let location = input.current_source_location();
|
||||||
let ident = input.expect_ident()?;
|
let ident = input.expect_ident()?;
|
||||||
Self::from_ident(ident.as_ref()).map_err(|()| {
|
Self::from_ident(ident.as_ref()).map_err(|()| {
|
||||||
location.new_unexpected_token_error(
|
location.new_unexpected_token_error(
|
||||||
::cssparser::Token::Ident(ident.clone())
|
cssparser::Token::Ident(ident.clone())
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
for param in input.generics.type_params() {
|
for param in input.generics.type_params() {
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(#param: ::style_traits::SpecifiedValueInfo),
|
parse_quote!(#param: style_traits::SpecifiedValueInfo),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
input.generics.where_clause = where_clause;
|
input.generics.where_clause = where_clause;
|
||||||
|
@ -86,20 +86,20 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
let mut types_value = quote!(0);
|
let mut types_value = quote!(0);
|
||||||
types_value.append_all(types.iter().map(|ty| {
|
types_value.append_all(types.iter().map(|ty| {
|
||||||
quote! {
|
quote! {
|
||||||
| <#ty as ::style_traits::SpecifiedValueInfo>::SUPPORTED_TYPES
|
| <#ty as style_traits::SpecifiedValueInfo>::SUPPORTED_TYPES
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let mut nested_collects = quote!();
|
let mut nested_collects = quote!();
|
||||||
nested_collects.append_all(types.iter().map(|ty| {
|
nested_collects.append_all(types.iter().map(|ty| {
|
||||||
quote! {
|
quote! {
|
||||||
<#ty as ::style_traits::SpecifiedValueInfo>::collect_completion_keywords(_f);
|
<#ty as style_traits::SpecifiedValueInfo>::collect_completion_keywords(_f);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if let Some(ty) = info_attrs.ty {
|
if let Some(ty) = info_attrs.ty {
|
||||||
types_value.append_all(quote! {
|
types_value.append_all(quote! {
|
||||||
| ::style_traits::CssType::#ty
|
| style_traits::CssType::#ty
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
let name = &input.ident;
|
let name = &input.ident;
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::style_traits::SpecifiedValueInfo for #name #ty_generics
|
impl #impl_generics style_traits::SpecifiedValueInfo for #name #ty_generics
|
||||||
#where_clause
|
#where_clause
|
||||||
{
|
{
|
||||||
const SUPPORTED_TYPES: u8 = #types_value;
|
const SUPPORTED_TYPES: u8 = #types_value;
|
||||||
|
|
|
@ -12,19 +12,19 @@ pub fn derive(mut input: DeriveInput) -> quote::Tokens {
|
||||||
for param in input.generics.type_params() {
|
for param in input.generics.type_params() {
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(#param: ::values::animated::ToAnimatedValue),
|
parse_quote!(#param: crate::values::animated::ToAnimatedValue),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let to_body = cg::fmap_match(
|
let to_body = cg::fmap_match(
|
||||||
&input,
|
&input,
|
||||||
BindStyle::Move,
|
BindStyle::Move,
|
||||||
|binding| quote!(::values::animated::ToAnimatedValue::to_animated_value(#binding)),
|
|binding| quote!(crate::values::animated::ToAnimatedValue::to_animated_value(#binding)),
|
||||||
);
|
);
|
||||||
let from_body = cg::fmap_match(
|
let from_body = cg::fmap_match(
|
||||||
&input,
|
&input,
|
||||||
BindStyle::Move,
|
BindStyle::Move,
|
||||||
|binding| quote!(::values::animated::ToAnimatedValue::from_animated_value(#binding)),
|
|binding| quote!(crate::values::animated::ToAnimatedValue::from_animated_value(#binding)),
|
||||||
);
|
);
|
||||||
|
|
||||||
input.generics.where_clause = where_clause;
|
input.generics.where_clause = where_clause;
|
||||||
|
@ -32,12 +32,12 @@ pub fn derive(mut input: DeriveInput) -> quote::Tokens {
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||||
let animated_value_type = cg::fmap_trait_output(
|
let animated_value_type = cg::fmap_trait_output(
|
||||||
&input,
|
&input,
|
||||||
&parse_quote!(values::animated::ToAnimatedValue),
|
&parse_quote!(crate::values::animated::ToAnimatedValue),
|
||||||
"AnimatedValue".into(),
|
"AnimatedValue".into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::values::animated::ToAnimatedValue for #name #ty_generics #where_clause {
|
impl #impl_generics crate::values::animated::ToAnimatedValue for #name #ty_generics #where_clause {
|
||||||
type AnimatedValue = #animated_value_type;
|
type AnimatedValue = #animated_value_type;
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens {
|
||||||
if !no_bound.contains(¶m.ident) {
|
if !no_bound.contains(¶m.ident) {
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(#param: ::values::animated::ToAnimatedZero),
|
parse_quote!(#param: crate::values::animated::ToAnimatedZero),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens {
|
||||||
let field_attrs = cg::parse_field_attrs::<AnimationFieldAttrs>(&binding.ast());
|
let field_attrs = cg::parse_field_attrs::<AnimationFieldAttrs>(&binding.ast());
|
||||||
if field_attrs.constant {
|
if field_attrs.constant {
|
||||||
quote! {
|
quote! {
|
||||||
let #mapped_binding = ::std::clone::Clone::clone(#binding);
|
let #mapped_binding = std::clone::Clone::clone(#binding);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
let #mapped_binding =
|
let #mapped_binding =
|
||||||
::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
|
crate::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -51,7 +51,7 @@ pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens {
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::values::animated::ToAnimatedZero for #name #ty_generics #where_clause {
|
impl #impl_generics crate::values::animated::ToAnimatedZero for #name #ty_generics #where_clause {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
for param in ¶ms {
|
for param in ¶ms {
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(#param: ::values::computed::ToComputedValue),
|
parse_quote!(#param: crate::values::computed::ToComputedValue),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,23 +26,23 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
let output_type = cg::map_type_params(
|
let output_type = cg::map_type_params(
|
||||||
ty,
|
ty,
|
||||||
¶ms,
|
¶ms,
|
||||||
&mut |ident| parse_quote!(<#ident as ::values::computed::ToComputedValue>::ComputedValue),
|
&mut |ident| parse_quote!(<#ident as crate::values::computed::ToComputedValue>::ComputedValue),
|
||||||
);
|
);
|
||||||
|
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(
|
parse_quote!(
|
||||||
#ty: ::values::computed::ToComputedValue<ComputedValue = #output_type>
|
#ty: crate::values::computed::ToComputedValue<ComputedValue = #output_type>
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
quote! {
|
quote! {
|
||||||
::values::computed::ToComputedValue::to_computed_value(#binding, context)
|
crate::values::computed::ToComputedValue::to_computed_value(#binding, context)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let from_body = cg::fmap_match(&input, BindStyle::Ref, |binding| {
|
let from_body = cg::fmap_match(&input, BindStyle::Ref, |binding| {
|
||||||
quote! {
|
quote! {
|
||||||
::values::computed::ToComputedValue::from_computed_value(#binding)
|
crate::values::computed::ToComputedValue::from_computed_value(#binding)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
|
|
||||||
if input.generics.type_params().next().is_none() {
|
if input.generics.type_params().next().is_none() {
|
||||||
return quote! {
|
return quote! {
|
||||||
impl #impl_generics ::values::computed::ToComputedValue for #name #ty_generics
|
impl #impl_generics crate::values::computed::ToComputedValue for #name #ty_generics
|
||||||
#where_clause
|
#where_clause
|
||||||
{
|
{
|
||||||
type ComputedValue = Self;
|
type ComputedValue = Self;
|
||||||
|
@ -63,14 +63,14 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(
|
fn to_computed_value(
|
||||||
&self,
|
&self,
|
||||||
_context: &::values::computed::Context,
|
_context: &crate::values::computed::Context,
|
||||||
) -> Self::ComputedValue {
|
) -> Self::ComputedValue {
|
||||||
::std::clone::Clone::clone(self)
|
std::clone::Clone::clone(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||||
::std::clone::Clone::clone(computed)
|
std::clone::Clone::clone(computed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -78,17 +78,17 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||||
|
|
||||||
let computed_value_type = cg::fmap_trait_output(
|
let computed_value_type = cg::fmap_trait_output(
|
||||||
&input,
|
&input,
|
||||||
&parse_quote!(values::computed::ToComputedValue),
|
&parse_quote!(crate::values::computed::ToComputedValue),
|
||||||
"ComputedValue".into(),
|
"ComputedValue".into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::values::computed::ToComputedValue for #name #ty_generics #where_clause {
|
impl #impl_generics crate::values::computed::ToComputedValue for #name #ty_generics #where_clause {
|
||||||
type ComputedValue = #computed_value_type;
|
type ComputedValue = #computed_value_type;
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, context: &::values::computed::Context) -> Self::ComputedValue {
|
fn to_computed_value(&self, context: &crate::values::computed::Context) -> Self::ComputedValue {
|
||||||
match *self {
|
match *self {
|
||||||
#to_body
|
#to_body
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub fn derive(mut input: syn::DeriveInput) -> Tokens {
|
||||||
for param in input.generics.type_params() {
|
for param in input.generics.type_params() {
|
||||||
cg::add_predicate(
|
cg::add_predicate(
|
||||||
&mut where_clause,
|
&mut where_clause,
|
||||||
parse_quote!(#param: ::style_traits::ToCss),
|
parse_quote!(#param: style_traits::ToCss),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,15 +36,15 @@ pub fn derive(mut input: syn::DeriveInput) -> Tokens {
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||||
|
|
||||||
let mut impls = quote! {
|
let mut impls = quote! {
|
||||||
impl #impl_generics ::style_traits::ToCss for #name #ty_generics #where_clause {
|
impl #impl_generics style_traits::ToCss for #name #ty_generics #where_clause {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_css<W>(
|
fn to_css<W>(
|
||||||
&self,
|
&self,
|
||||||
dest: &mut ::style_traits::CssWriter<W>,
|
dest: &mut style_traits::CssWriter<W>,
|
||||||
) -> ::std::fmt::Result
|
) -> std::fmt::Result
|
||||||
where
|
where
|
||||||
W: ::std::fmt::Write,
|
W: std::fmt::Write,
|
||||||
{
|
{
|
||||||
match *self {
|
match *self {
|
||||||
#match_body
|
#match_body
|
||||||
|
@ -55,11 +55,11 @@ pub fn derive(mut input: syn::DeriveInput) -> Tokens {
|
||||||
|
|
||||||
if input_attrs.derive_debug {
|
if input_attrs.derive_debug {
|
||||||
impls.append_all(quote! {
|
impls.append_all(quote! {
|
||||||
impl #impl_generics ::std::fmt::Debug for #name #ty_generics #where_clause {
|
impl #impl_generics std::fmt::Debug for #name #ty_generics #where_clause {
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
::style_traits::ToCss::to_css(
|
style_traits::ToCss::to_css(
|
||||||
self,
|
self,
|
||||||
&mut ::style_traits::CssWriter::new(f),
|
&mut style_traits::CssWriter::new(f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,28 +90,28 @@ fn derive_variant_arm(variant: &VariantInfo, generics: &mut Option<WhereClause>)
|
||||||
let mut expr = if let Some(keyword) = variant_attrs.keyword {
|
let mut expr = if let Some(keyword) = variant_attrs.keyword {
|
||||||
assert!(bindings.is_empty());
|
assert!(bindings.is_empty());
|
||||||
quote! {
|
quote! {
|
||||||
::std::fmt::Write::write_str(dest, #keyword)
|
std::fmt::Write::write_str(dest, #keyword)
|
||||||
}
|
}
|
||||||
} else if !bindings.is_empty() {
|
} else if !bindings.is_empty() {
|
||||||
derive_variant_fields_expr(bindings, generics, separator)
|
derive_variant_fields_expr(bindings, generics, separator)
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
::std::fmt::Write::write_str(dest, #identifier)
|
std::fmt::Write::write_str(dest, #identifier)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if variant_attrs.dimension {
|
if variant_attrs.dimension {
|
||||||
expr = quote! {
|
expr = quote! {
|
||||||
#expr?;
|
#expr?;
|
||||||
::std::fmt::Write::write_str(dest, #identifier)
|
std::fmt::Write::write_str(dest, #identifier)
|
||||||
}
|
}
|
||||||
} else if let Some(function) = variant_attrs.function {
|
} else if let Some(function) = variant_attrs.function {
|
||||||
let mut identifier = function.explicit().map_or(identifier, |name| name);
|
let mut identifier = function.explicit().map_or(identifier, |name| name);
|
||||||
identifier.push_str("(");
|
identifier.push_str("(");
|
||||||
expr = quote! {
|
expr = quote! {
|
||||||
::std::fmt::Write::write_str(dest, #identifier)?;
|
std::fmt::Write::write_str(dest, #identifier)?;
|
||||||
#expr?;
|
#expr?;
|
||||||
::std::fmt::Write::write_str(dest, ")")
|
std::fmt::Write::write_str(dest, ")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expr
|
expr
|
||||||
|
@ -140,9 +140,9 @@ fn derive_variant_fields_expr(
|
||||||
if !attrs.iterable && iter.peek().is_none() {
|
if !attrs.iterable && iter.peek().is_none() {
|
||||||
if attrs.field_bound {
|
if attrs.field_bound {
|
||||||
let ty = &first.ast().ty;
|
let ty = &first.ast().ty;
|
||||||
cg::add_predicate(where_clause, parse_quote!(#ty: ::style_traits::ToCss));
|
cg::add_predicate(where_clause, parse_quote!(#ty: style_traits::ToCss));
|
||||||
}
|
}
|
||||||
let mut expr = quote! { ::style_traits::ToCss::to_css(#first, dest) };
|
let mut expr = quote! { style_traits::ToCss::to_css(#first, dest) };
|
||||||
if let Some(condition) = attrs.skip_if {
|
if let Some(condition) = attrs.skip_if {
|
||||||
expr = quote! {
|
expr = quote! {
|
||||||
if !#condition(#first) {
|
if !#condition(#first) {
|
||||||
|
@ -159,7 +159,7 @@ fn derive_variant_fields_expr(
|
||||||
}
|
}
|
||||||
|
|
||||||
quote! {{
|
quote! {{
|
||||||
let mut writer = ::style_traits::values::SequenceWriter::new(dest, #separator);
|
let mut writer = style_traits::values::SequenceWriter::new(dest, #separator);
|
||||||
#expr
|
#expr
|
||||||
Ok(())
|
Ok(())
|
||||||
}}
|
}}
|
||||||
|
@ -205,7 +205,7 @@ fn derive_single_field_expr(
|
||||||
} else {
|
} else {
|
||||||
if attrs.field_bound {
|
if attrs.field_bound {
|
||||||
let ty = &field.ast().ty;
|
let ty = &field.ast().ty;
|
||||||
cg::add_predicate(where_clause, parse_quote!(#ty: ::style_traits::ToCss));
|
cg::add_predicate(where_clause, parse_quote!(#ty: style_traits::ToCss));
|
||||||
}
|
}
|
||||||
quote! { writer.item(#field)?; }
|
quote! { writer.item(#field)?; }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue