• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Alorel / fancy_constructor-rs / 14957680780

11 May 2025 04:32PM UTC coverage: 97.708%. First build
14957680780

Pull #12

github

web-flow
Merge 067eea501 into 0af134203
Pull Request #12: feat: Option to derive `Default` trait

127 of 133 new or added lines in 7 files covered. (95.49%)

341 of 349 relevant lines covered (97.71%)

6.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/src/types/fields_source.rs
1
use super::{Field, Fields};
2
use crate::FmtTuple;
3
use proc_macro2::Ident;
4
use quote::format_ident;
5
use syn::Error;
6

7
pub enum FieldsSource {
8
    Struct(Fields),
9
    Enum { variant: Ident, fields: Fields },
10
}
11

12
impl FieldsSource {
13
    pub(crate) fn fields(&self) -> &Fields {
10✔
14
        match *self {
10✔
15
            FieldsSource::Struct(ref fields) | FieldsSource::Enum { ref fields, .. } => fields,
10✔
16
        }
10✔
17
    }
10✔
18
}
19

20
impl TryFrom<syn::Fields> for Fields {
21
    type Error = Error;
22

23
    fn try_from(fields: syn::Fields) -> Result<Self, Self::Error> {
9✔
24
        Ok(match fields {
9✔
NEW
25
            syn::Fields::Unit => Fields::Unit,
×
26
            syn::Fields::Named(f) => Fields::Named(Field::collect(fmt_named(f.named))?),
7✔
27
            syn::Fields::Unnamed(f) => Fields::Unnamed(Field::collect(fmt_unnamed(f.unnamed))?),
2✔
28
        })
29
    }
9✔
30
}
31

32
fn fmt_named(fields: impl IntoIterator<Item = syn::Field>) -> impl Iterator<Item = FmtTuple> {
7✔
33
    fields.into_iter().map(move |f| {
13✔
34
        (
13✔
35
            f.attrs,
13✔
36
            Ok(f.ident.expect("Failed to get ident off a named field")),
13✔
37
            f.ty,
13✔
38
        )
13✔
39
    })
13✔
40
}
7✔
41

42
fn fmt_unnamed(fields: impl IntoIterator<Item = syn::Field>) -> impl Iterator<Item = FmtTuple> {
2✔
43
    fields
2✔
44
        .into_iter()
2✔
45
        .enumerate()
2✔
46
        .map(move |(i, syn::Field { attrs, ty, .. })| (attrs, Err(format_ident!("f{}", i + 1)), ty))
2✔
47
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc