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

Alorel / delegate-display-rs / 11355618640

15 Oct 2024 10:51PM UTC coverage: 93.118%. Remained the same
11355618640

push

github

Alorel
feat: Support deriving multiple traits at once

BREAKING CHANGE: `dboth` attribute renamed to `dany`

81 of 85 new or added lines in 6 files covered. (95.29%)

9 existing lines in 1 file now uncovered.

433 of 465 relevant lines covered (93.12%)

8.8 hits per line

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

84.62
/src/implementation/dual_attr.rs
1
use crate::ATTR_ANY;
2
use impartial_ord::ImpartialOrd;
3
use std::cmp::Ordering;
4
use syn::Attribute;
5

6
#[derive(ImpartialOrd)]
7
pub(crate) struct DualAttr {
8
    pub attr_ty: AttrKind,
9
    pub attr: Attribute,
10
}
11

12
#[derive(Copy, Clone, Eq, PartialEq, Ord, ImpartialOrd)]
13
pub(crate) enum AttrKind {
14
    CatchAll,
15
    Primary,
16
}
17

18
impl AttrKind {
19
    pub fn aggregate<I>(attrs: I, attr_name: &str) -> Option<Self>
32✔
20
    where
32✔
21
        I: IntoIterator<Item = Attribute>,
32✔
22
    {
32✔
23
        DualAttr::collect(attrs, attr_name)
32✔
24
            .last()
32✔
25
            .map(move |a| a.attr_ty)
32✔
26
    }
32✔
27
}
28

29
impl DualAttr {
30
    pub fn collect<I>(attrs: I, attr_name: &str) -> Vec<Self>
53✔
31
    where
53✔
32
        I: IntoIterator<Item = Attribute>,
53✔
33
    {
53✔
34
        let mut out = attrs
53✔
35
            .into_iter()
53✔
36
            .filter_map(|a| Self::from_syn(a, attr_name))
53✔
37
            .collect::<Vec<_>>();
53✔
38

53✔
39
        out.sort();
53✔
40

53✔
41
        out
53✔
42
    }
53✔
43

44
    pub fn from_syn(attr: Attribute, attr_name: &str) -> Option<Self> {
11✔
45
        let ident = attr.path().get_ident()?;
11✔
46
        let ident_str = ident.to_string();
11✔
47

11✔
48
        Some(Self {
11✔
49
            attr_ty: if ident_str == attr_name {
11✔
50
                AttrKind::Primary
6✔
51
            } else if ident_str == ATTR_ANY {
5✔
52
                AttrKind::CatchAll
3✔
53
            } else {
54
                return None;
2✔
55
            },
56
            attr,
9✔
57
        })
58
    }
11✔
59
}
60

61
impl PartialEq for DualAttr {
62
    #[inline]
63
    fn eq(&self, other: &Self) -> bool {
×
64
        self.attr_ty == other.attr_ty
×
65
    }
×
66
}
67

68
impl Eq for DualAttr {}
69

70
#[allow(clippy::derive_ord_xor_partial_ord)]
71
impl Ord for DualAttr {
72
    #[inline]
73
    fn cmp(&self, other: &Self) -> Ordering {
×
74
        self.attr_ty.cmp(&other.attr_ty)
×
75
    }
×
76
}
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

© 2025 Coveralls, Inc