Struct attr_parser_fn::ParseArgs

source ·
pub struct ParseArgs<ReqArgs, OptArgs, RestArgs, Meta> {
    pub args: ReqArgs,
    pub opt_args: OptArgs,
    pub rest_args: RestArgs,
    pub meta: Meta,
}

Fields§

§args: ReqArgs§opt_args: OptArgs§rest_args: RestArgs§meta: Meta

Implementations§

source§

impl ParseArgs<Marker<()>, Marker<()>, Marker<()>, ()>

source

pub fn new() -> Self

Examples found in repository?
examples/test.rs (line 21)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
fn main() {
    let attr: Attribute = parse_quote! {
        #[my_attr(
            "hello",
            "world",
            122,
            conf1 = 114 + 514,
            key_value = SomeType<A, B>,
            path_only,
            nested(tea(green_tea)))
        ]
    };

    let parser = ParseArgs::new()
        .args::<(LitStr, LitStr)>()
        .opt_args::<(Lit, Lit)>()
        .rest_args::<Vec<Lit>>()
        .meta((
            ("path_only", path_only()),
            ("key_value", key_value::<Type>()),
            ("kv_optional", key_value::<Expr>()).optional(),
            conflicts((
                ("conf1", path_only()).value("conf1"),
                ("conf1", key_value::<Expr>()).value("conf1_expr"),
                ("conf2", key_value::<Expr>()).value("conf2"),
            )),
            (
                "nested",
                meta_list((
                    ("milk", path_only()),
                    (
                        "tea",
                        meta_list(conflicts((
                            ("red_tea", path_only()).value("red_tea"),
                            ("green_tea", path_only()).value("green_tea"),
                        ))),
                    ),
                )),
            ),
        ));

    let ParseArgs {
        args: (_, _),              // ("hello", "world")
        opt_args: (Some(_), None), // (Some(112), None)
        rest_args: _,              // []
        meta:
            (
                true,
                _, // SomeType<A, B>
                None,
                "conf1_expr",
                (false, "green_tea"),
            ),
    } = parser.parse_attrs(&attr).unwrap()
    else {
        unreachable!()
    };
}
source§

impl<ReqArgs, OptArgs, RestArgs, Meta> ParseArgs<ReqArgs, OptArgs, RestArgs, Meta>

source

pub fn args<T: ParseRequiredArgs>( self, ) -> ParseArgs<Marker<T>, OptArgs, RestArgs, Meta>

Examples found in repository?
examples/test.rs (line 22)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
fn main() {
    let attr: Attribute = parse_quote! {
        #[my_attr(
            "hello",
            "world",
            122,
            conf1 = 114 + 514,
            key_value = SomeType<A, B>,
            path_only,
            nested(tea(green_tea)))
        ]
    };

    let parser = ParseArgs::new()
        .args::<(LitStr, LitStr)>()
        .opt_args::<(Lit, Lit)>()
        .rest_args::<Vec<Lit>>()
        .meta((
            ("path_only", path_only()),
            ("key_value", key_value::<Type>()),
            ("kv_optional", key_value::<Expr>()).optional(),
            conflicts((
                ("conf1", path_only()).value("conf1"),
                ("conf1", key_value::<Expr>()).value("conf1_expr"),
                ("conf2", key_value::<Expr>()).value("conf2"),
            )),
            (
                "nested",
                meta_list((
                    ("milk", path_only()),
                    (
                        "tea",
                        meta_list(conflicts((
                            ("red_tea", path_only()).value("red_tea"),
                            ("green_tea", path_only()).value("green_tea"),
                        ))),
                    ),
                )),
            ),
        ));

    let ParseArgs {
        args: (_, _),              // ("hello", "world")
        opt_args: (Some(_), None), // (Some(112), None)
        rest_args: _,              // []
        meta:
            (
                true,
                _, // SomeType<A, B>
                None,
                "conf1_expr",
                (false, "green_tea"),
            ),
    } = parser.parse_attrs(&attr).unwrap()
    else {
        unreachable!()
    };
}
source

pub fn opt_args<T: ParseOptionalArgs>( self, ) -> ParseArgs<ReqArgs, Marker<T>, RestArgs, Meta>

Examples found in repository?
examples/test.rs (line 23)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
fn main() {
    let attr: Attribute = parse_quote! {
        #[my_attr(
            "hello",
            "world",
            122,
            conf1 = 114 + 514,
            key_value = SomeType<A, B>,
            path_only,
            nested(tea(green_tea)))
        ]
    };

    let parser = ParseArgs::new()
        .args::<(LitStr, LitStr)>()
        .opt_args::<(Lit, Lit)>()
        .rest_args::<Vec<Lit>>()
        .meta((
            ("path_only", path_only()),
            ("key_value", key_value::<Type>()),
            ("kv_optional", key_value::<Expr>()).optional(),
            conflicts((
                ("conf1", path_only()).value("conf1"),
                ("conf1", key_value::<Expr>()).value("conf1_expr"),
                ("conf2", key_value::<Expr>()).value("conf2"),
            )),
            (
                "nested",
                meta_list((
                    ("milk", path_only()),
                    (
                        "tea",
                        meta_list(conflicts((
                            ("red_tea", path_only()).value("red_tea"),
                            ("green_tea", path_only()).value("green_tea"),
                        ))),
                    ),
                )),
            ),
        ));

    let ParseArgs {
        args: (_, _),              // ("hello", "world")
        opt_args: (Some(_), None), // (Some(112), None)
        rest_args: _,              // []
        meta:
            (
                true,
                _, // SomeType<A, B>
                None,
                "conf1_expr",
                (false, "green_tea"),
            ),
    } = parser.parse_attrs(&attr).unwrap()
    else {
        unreachable!()
    };
}
source

pub fn rest_args<T: ParseRestArgs>( self, ) -> ParseArgs<ReqArgs, OptArgs, Marker<T>, Meta>

Examples found in repository?
examples/test.rs (line 24)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
fn main() {
    let attr: Attribute = parse_quote! {
        #[my_attr(
            "hello",
            "world",
            122,
            conf1 = 114 + 514,
            key_value = SomeType<A, B>,
            path_only,
            nested(tea(green_tea)))
        ]
    };

    let parser = ParseArgs::new()
        .args::<(LitStr, LitStr)>()
        .opt_args::<(Lit, Lit)>()
        .rest_args::<Vec<Lit>>()
        .meta((
            ("path_only", path_only()),
            ("key_value", key_value::<Type>()),
            ("kv_optional", key_value::<Expr>()).optional(),
            conflicts((
                ("conf1", path_only()).value("conf1"),
                ("conf1", key_value::<Expr>()).value("conf1_expr"),
                ("conf2", key_value::<Expr>()).value("conf2"),
            )),
            (
                "nested",
                meta_list((
                    ("milk", path_only()),
                    (
                        "tea",
                        meta_list(conflicts((
                            ("red_tea", path_only()).value("red_tea"),
                            ("green_tea", path_only()).value("green_tea"),
                        ))),
                    ),
                )),
            ),
        ));

    let ParseArgs {
        args: (_, _),              // ("hello", "world")
        opt_args: (Some(_), None), // (Some(112), None)
        rest_args: _,              // []
        meta:
            (
                true,
                _, // SomeType<A, B>
                None,
                "conf1_expr",
                (false, "green_tea"),
            ),
    } = parser.parse_attrs(&attr).unwrap()
    else {
        unreachable!()
    };
}
source

pub fn meta<T: ParseMeta>( self, meta: T, ) -> ParseArgs<ReqArgs, OptArgs, RestArgs, T>

Examples found in repository?
examples/test.rs (lines 25-47)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
fn main() {
    let attr: Attribute = parse_quote! {
        #[my_attr(
            "hello",
            "world",
            122,
            conf1 = 114 + 514,
            key_value = SomeType<A, B>,
            path_only,
            nested(tea(green_tea)))
        ]
    };

    let parser = ParseArgs::new()
        .args::<(LitStr, LitStr)>()
        .opt_args::<(Lit, Lit)>()
        .rest_args::<Vec<Lit>>()
        .meta((
            ("path_only", path_only()),
            ("key_value", key_value::<Type>()),
            ("kv_optional", key_value::<Expr>()).optional(),
            conflicts((
                ("conf1", path_only()).value("conf1"),
                ("conf1", key_value::<Expr>()).value("conf1_expr"),
                ("conf2", key_value::<Expr>()).value("conf2"),
            )),
            (
                "nested",
                meta_list((
                    ("milk", path_only()),
                    (
                        "tea",
                        meta_list(conflicts((
                            ("red_tea", path_only()).value("red_tea"),
                            ("green_tea", path_only()).value("green_tea"),
                        ))),
                    ),
                )),
            ),
        ));

    let ParseArgs {
        args: (_, _),              // ("hello", "world")
        opt_args: (Some(_), None), // (Some(112), None)
        rest_args: _,              // []
        meta:
            (
                true,
                _, // SomeType<A, B>
                None,
                "conf1_expr",
                (false, "green_tea"),
            ),
    } = parser.parse_attrs(&attr).unwrap()
    else {
        unreachable!()
    };
}

Trait Implementations§

source§

impl<ReqArgs: Debug, OptArgs: Debug, RestArgs: Debug, Meta: Debug> Debug for ParseArgs<ReqArgs, OptArgs, RestArgs, Meta>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<ReqArgs, OptArgs, RestArgs, Meta> ParseAttrTrait for ParseArgs<Marker<ReqArgs>, Marker<OptArgs>, Marker<RestArgs>, Meta>
where ReqArgs: ParseRequiredArgs, OptArgs: ParseOptionalArgs, RestArgs: ParseRestArgs, Meta: ParseMeta,

§

type Output = ParseArgs<<ReqArgs as ParseRequiredArgs>::Output, <OptArgs as ParseOptionalArgs>::Output, RestArgs, <Meta as ParseMeta>::Output>

source§

fn parse(self, input: ParseStream<'_>) -> Result<Self::Output>

source§

fn parse_attrs(self, input: &Attribute) -> Result<Self::Output>

Auto Trait Implementations§

§

impl<ReqArgs, OptArgs, RestArgs, Meta> Freeze for ParseArgs<ReqArgs, OptArgs, RestArgs, Meta>
where ReqArgs: Freeze, OptArgs: Freeze, RestArgs: Freeze, Meta: Freeze,

§

impl<ReqArgs, OptArgs, RestArgs, Meta> RefUnwindSafe for ParseArgs<ReqArgs, OptArgs, RestArgs, Meta>
where ReqArgs: RefUnwindSafe, OptArgs: RefUnwindSafe, RestArgs: RefUnwindSafe, Meta: RefUnwindSafe,

§

impl<ReqArgs, OptArgs, RestArgs, Meta> Send for ParseArgs<ReqArgs, OptArgs, RestArgs, Meta>
where ReqArgs: Send, OptArgs: Send, RestArgs: Send, Meta: Send,

§

impl<ReqArgs, OptArgs, RestArgs, Meta> Sync for ParseArgs<ReqArgs, OptArgs, RestArgs, Meta>
where ReqArgs: Sync, OptArgs: Sync, RestArgs: Sync, Meta: Sync,

§

impl<ReqArgs, OptArgs, RestArgs, Meta> Unpin for ParseArgs<ReqArgs, OptArgs, RestArgs, Meta>
where ReqArgs: Unpin, OptArgs: Unpin, RestArgs: Unpin, Meta: Unpin,

§

impl<ReqArgs, OptArgs, RestArgs, Meta> UnwindSafe for ParseArgs<ReqArgs, OptArgs, RestArgs, Meta>
where ReqArgs: UnwindSafe, OptArgs: UnwindSafe, RestArgs: UnwindSafe, Meta: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.