Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include example published package #369

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ include = [
"README.md",
"CHANGELOG.md",
"tests/**/*.rs", # debian packaging wants this
"examples/**/*.rs"
]

[workspace]
Expand All @@ -43,6 +44,9 @@ github = { repository = "JelteF/derive_more", workflow = "CI" }
features = ["full"]
rustdoc-args = ["--cfg", "docsrs"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] }

[features]
default = ["std"]

Expand Down
3 changes: 3 additions & 0 deletions impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ github = { repository = "JelteF/derive_more", workflow = "CI" }
features = ["full"]
rustdoc-args = ["--cfg", "docsrs"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] }

[features]
default = []

Expand Down
38 changes: 19 additions & 19 deletions impl/src/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,25 @@ impl From<StructAttribute> for ConversionsAttribute {
}
}

type Untyped = Either<attr::Skip, Either<attr::Empty, ConversionsAttribute>>;
impl From<Untyped> for FieldAttribute {
fn from(v: Untyped) -> Self {
match v {
Untyped::Left(skip) => Self {
skip: Some(skip),
convs: None,
},
Untyped::Right(c) => Self {
skip: None,
convs: Some(match c {
Either::Left(_empty) => ConversionsAttribute::default(),
Either::Right(convs) => convs,
}),
},
}
}
}

/// Representation of an [`Into`] derive macro field attribute.
///
/// ```rust,ignore
Expand All @@ -242,25 +261,6 @@ impl attr::ParseMultiple for FieldAttribute {
attr: &syn::Attribute,
parser: &P,
) -> syn::Result<Self> {
type Untyped = Either<attr::Skip, Either<attr::Empty, ConversionsAttribute>>;
impl From<Untyped> for FieldAttribute {
fn from(v: Untyped) -> Self {
match v {
Untyped::Left(skip) => Self {
skip: Some(skip),
convs: None,
},
Untyped::Right(c) => Self {
skip: None,
convs: Some(match c {
Either::Left(_empty) => ConversionsAttribute::default(),
Either::Right(convs) => convs,
}),
},
}
}
}

Untyped::parse_attr_with(attr, parser).map(Self::from)
}

Expand Down
20 changes: 1 addition & 19 deletions impl/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ pub enum DeriveType {
pub struct State<'input> {
pub input: &'input DeriveInput,
pub trait_name: &'static str,
pub trait_ident: Ident,
pub method_ident: Ident,
pub trait_path: TokenStream,
pub trait_path_params: Vec<TokenStream>,
Expand Down Expand Up @@ -417,8 +416,7 @@ impl<'input> State<'input> {
let meta_infos = meta_infos?;
let first_match = meta_infos
.iter()
.filter_map(|info| info.enabled.map(|_| info))
.next();
.find_map(|info| info.enabled.map(|_| info));

// Default to enabled true, except when first attribute has explicit
// enabling.
Expand Down Expand Up @@ -489,7 +487,6 @@ impl<'input> State<'input> {
Ok(State {
input,
trait_name,
trait_ident,
method_ident,
trait_path,
trait_path_params: vec![],
Expand Down Expand Up @@ -546,7 +543,6 @@ impl<'input> State<'input> {
trait_path,
trait_path_params: vec![],
trait_attr,
trait_ident,
method_ident,
// input,
fields,
Expand Down Expand Up @@ -579,7 +575,6 @@ impl<'input> State<'input> {
field_type: data.field_types[0],
member: data.members[0].clone(),
info: data.infos[0].clone(),
field_ident: data.field_idents[0].clone(),
trait_path: data.trait_path,
trait_path_with_params: data.trait_path_with_params.clone(),
casted_trait: data.casted_traits[0].clone(),
Expand Down Expand Up @@ -652,17 +647,10 @@ impl<'input> State<'input> {
panic!("can only derive({}) for enum", self.trait_name)
}
let variants = self.enabled_variants();
let trait_path = &self.trait_path;
let (impl_generics, ty_generics, where_clause) = self.generics.split_for_impl();
MultiVariantData {
input_type: &self.input.ident,
variants,
variant_states: self.enabled_variant_states(),
infos: self.enabled_infos(),
trait_path,
impl_generics,
ty_generics,
where_clause,
}
}

Expand Down Expand Up @@ -744,7 +732,6 @@ pub struct SingleFieldData<'input, 'state> {
pub input_type: &'input Ident,
pub field: &'input Field,
pub field_type: &'input Type,
pub field_ident: TokenStream,
pub member: TokenStream,
pub info: FullMetaInfo,
pub trait_path: &'state TokenStream,
Expand Down Expand Up @@ -779,14 +766,9 @@ pub struct MultiFieldData<'input, 'state> {
}

pub struct MultiVariantData<'input, 'state> {
pub input_type: &'input Ident,
pub variants: Vec<&'input Variant>,
pub variant_states: Vec<&'state State<'input>>,
pub infos: Vec<FullMetaInfo>,
pub trait_path: &'state TokenStream,
pub impl_generics: ImplGenerics<'state>,
pub ty_generics: TypeGenerics<'state>,
pub where_clause: Option<&'state WhereClause>,
}

impl<'input, 'state> MultiFieldData<'input, 'state> {
Expand Down