/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use darling::{FromDeriveInput, FromField, FromVariant}; use proc_macro2::{Span, TokenStream}; use quote::{quote, TokenStreamExt}; use syn::parse_quote; use syn::{self, AngleBracketedGenericArguments, AssocType, DeriveInput, Field}; use syn::{GenericArgument, GenericParam, Ident, Path}; use syn::{PathArguments, PathSegment, QSelf, Type, TypeArray, TypeGroup}; use syn::{TypeParam, TypeParen, TypePath, TypeSlice, TypeTuple}; use syn::{Variant, WherePredicate}; use synstructure::{self, BindStyle, BindingInfo, VariantAst, VariantInfo};
/// Given an input type which has some where clauses already, like: /// /// struct InputType<T> /// where /// T: Zero, /// { /// ... /// } /// /// Add the necessary `where` clauses so that the output type of a trait /// fulfils them. /// /// For example: /// /// ```ignore /// <T as ToComputedValue>::ComputedValue: Zero, /// ``` /// /// This needs to run before adding other bounds to the type parameters. pub(crate) fn propagate_clauses_to_output_type(
where_clause: &mut Option<syn::WhereClause>,
generics: &syn::Generics,
trait_path: &Path,
trait_output: &Ident,
) { let where_clause = match *where_clause {
Some(refmut clause) => clause,
None => return,
}; letmut extra_bounds = vec![]; for pred in &where_clause.predicates { let ty = match *pred {
syn::WherePredicate::Type(ref ty) => ty, ref predicate => panic!("Unhanded complex where predicate: {:?}", predicate),
};
let path = match ty.bounded_ty {
syn::Type::Path(ref p) => &p.path, ref ty => panic!("Unhanded complex where type: {:?}", ty),
};
let ident = match path_to_ident(path) {
Some(i) => i,
None => panic!("Unhanded complex where type path: {:?}", path),
};
if generics.type_params().any(|param| param.ident == *ident) {
extra_bounds.push(ty.clone());
}
}
for bound in extra_bounds { let ty = bound.bounded_ty; let bounds = bound.bounds;
where_clause
.predicates
.push(parse_quote!(<#tyas#trait_path>::#trait_output: #bounds))
}
}
/// Transforms "FooBar" to "foo-bar". /// /// If the first Camel segment is "Moz", "Webkit", or "Servo", the result string /// is prepended with "-". pub(crate) fn to_css_identifier(mut camel_case: &str) -> String {
camel_case = camel_case.trim_end_matches('_'); letmut first = true; letmut result = String::with_capacity(camel_case.len()); whilelet Some(segment) = split_camel_segment(&mut camel_case) { if first { match segment { "Moz" | "Webkit" | "Servo" => first = false,
_ => {},
}
} if !first {
result.push('-');
}
first = false;
result.push_str(&segment.to_lowercase());
}
result
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.