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

Alorel / delegate-display-rs / 11550909325

28 Oct 2024 09:19AM UTC coverage: 93.118%. First build
11550909325

Pull #13

github

web-flow
Merge 90c44bead into e44b91622
Pull Request #13: deps: bump alorel-actions/cargo from 1 to 2

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

100.0
/src/implementation/opts.rs
1
use super::compound::Alias;
2
use super::dual_attr::DualAttr;
3
use macroific::prelude::*;
4
use std::iter::FusedIterator;
5
use std::ops::{Add, AddAssign};
6
use syn::punctuated::Punctuated;
7
use syn::{Attribute, Token, Type, WherePredicate};
8

9
#[derive(AttributeOptions, ParseOption, Default, Clone)]
3✔
10
pub(crate) struct ContainerOptions {
11
    pub bounds: Punctuated<WherePredicate, Token![,]>,
12
    pub delegate_to: Option<Type>,
13
}
14

15
#[derive(AttributeOptions, Default)]
4✔
16
pub(crate) struct MultiContainerOptions {
17
    dany: Option<ContainerOptions>,
18
    dbinary: Option<ContainerOptions>,
19
    ddebug: Option<ContainerOptions>,
20
    ddisplay: Option<ContainerOptions>,
21
    dlexp: Option<ContainerOptions>,
22
    dlhex: Option<ContainerOptions>,
23
    doctal: Option<ContainerOptions>,
24
    dpointer: Option<ContainerOptions>,
25
    duexp: Option<ContainerOptions>,
26
    duhex: Option<ContainerOptions>,
27
}
28

29
impl ContainerOptions {
30
    pub fn resolve<I>(attrs: I, attr_name: &str) -> syn::Result<Self>
21✔
31
    where
21✔
32
        I: IntoIterator<Item = Attribute>,
21✔
33
    {
21✔
34
        let attrs = DualAttr::collect(attrs, attr_name);
21✔
35
        let mut out = Self::default();
21✔
36

37
        for dattr in attrs {
23✔
38
            let opts = ContainerOptions::from_attr(dattr.attr)?;
2✔
39
            out += opts;
2✔
40
        }
41

42
        Ok(out)
21✔
43
    }
21✔
44
}
45

46
impl AddAssign for ContainerOptions {
47
    fn add_assign(&mut self, rhs: Self) {
5✔
48
        let Self {
5✔
49
            bounds: bounds_l,
5✔
50
            delegate_to: delegate_to_l,
5✔
51
        } = self;
5✔
52

5✔
53
        let Self {
5✔
54
            bounds: bounds_r,
5✔
55
            delegate_to: delegate_to_r,
5✔
56
        } = rhs;
5✔
57

5✔
58
        bounds_l.extend(bounds_r);
5✔
59

60
        if let Some(delegate_to) = delegate_to_r {
5✔
61
            *delegate_to_l = Some(delegate_to);
2✔
62
        }
3✔
63
    }
5✔
64
}
65

66
impl Add<ContainerOptions> for &ContainerOptions {
67
    type Output = ContainerOptions;
68

69
    fn add(self, rhs: ContainerOptions) -> Self::Output {
3✔
70
        let mut out = self.clone();
3✔
71
        out += rhs;
3✔
72
        out
3✔
73
    }
3✔
74
}
75

76
impl MultiContainerOptions {
77
    pub fn into_iter(self) -> impl FusedIterator<Item = (Alias<'static>, ContainerOptions)> {
1✔
78
        let Self {
1✔
79
            dany,
1✔
80
            dbinary,
1✔
81
            ddebug,
1✔
82
            ddisplay,
1✔
83
            dlexp,
1✔
84
            dlhex,
1✔
85
            doctal,
1✔
86
            dpointer,
1✔
87
            duexp,
1✔
88
            duhex,
1✔
89
        } = self;
1✔
90

91
        macro_rules! iter {
92
            ($default: ident | [$($id: ident),+ $(,)?] $(,)?) => {{
93
                let default = $default.unwrap_or_default();
94
                let arr = [$($id.map(|v| (Alias::$id, &default + v))),+];
3✔
95
                ::std::iter::IntoIterator::into_iter(arr)
96
            }};
97
        }
98

99
        let options = iter!(
1✔
100
            dany | [dbinary, ddebug, ddisplay, dlexp, dlhex, doctal, dpointer, duexp, duhex,]
1✔
101
        );
1✔
102

1✔
103
        options.flatten()
1✔
104
    }
1✔
105
}
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