ParseArgs

Struct 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)
8fn main() {
9    let attr: Attribute = parse_quote! {
10        #[my_attr(
11            "hello",
12            "world",
13            122,
14            conf1 = 114 + 514,
15            key_value = SomeType<A, B>,
16            path_only,
17            nested(tea(green_tea)))
18        ]
19    };
20
21    let parser = ParseArgs::new()
22        .args::<(LitStr, LitStr)>()
23        .opt_args::<(Lit, Lit)>()
24        .rest_args::<Vec<Lit>>()
25        .meta((
26            ("path_only", path_only()),
27            ("key_value", key_value::<Type>()),
28            ("kv_optional", key_value::<Expr>()).optional(),
29            conflicts((
30                ("conf1", path_only()).value("conf1"),
31                ("conf1", key_value::<Expr>()).value("conf1_expr"),
32                ("conf2", key_value::<Expr>()).value("conf2"),
33            )),
34            (
35                "nested",
36                meta_list((
37                    ("milk", path_only()),
38                    (
39                        "tea",
40                        meta_list(conflicts((
41                            ("red_tea", path_only()).value("red_tea"),
42                            ("green_tea", path_only()).value("green_tea"),
43                        ))),
44                    ),
45                )),
46            ),
47        ));
48
49    let ParseArgs {
50        args: (_, _),              // ("hello", "world")
51        opt_args: (Some(_), None), // (Some(112), None)
52        rest_args: _,              // []
53        meta:
54            (
55                true,
56                _, // SomeType<A, B>
57                None,
58                "conf1_expr",
59                (false, "green_tea"),
60            ),
61    } = parser.parse_attr(&attr).unwrap()
62    else {
63        unreachable!()
64    };
65}
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)
8fn main() {
9    let attr: Attribute = parse_quote! {
10        #[my_attr(
11            "hello",
12            "world",
13            122,
14            conf1 = 114 + 514,
15            key_value = SomeType<A, B>,
16            path_only,
17            nested(tea(green_tea)))
18        ]
19    };
20
21    let parser = ParseArgs::new()
22        .args::<(LitStr, LitStr)>()
23        .opt_args::<(Lit, Lit)>()
24        .rest_args::<Vec<Lit>>()
25        .meta((
26            ("path_only", path_only()),
27            ("key_value", key_value::<Type>()),
28            ("kv_optional", key_value::<Expr>()).optional(),
29            conflicts((
30                ("conf1", path_only()).value("conf1"),
31                ("conf1", key_value::<Expr>()).value("conf1_expr"),
32                ("conf2", key_value::<Expr>()).value("conf2"),
33            )),
34            (
35                "nested",
36                meta_list((
37                    ("milk", path_only()),
38                    (
39                        "tea",
40                        meta_list(conflicts((
41                            ("red_tea", path_only()).value("red_tea"),
42                            ("green_tea", path_only()).value("green_tea"),
43                        ))),
44                    ),
45                )),
46            ),
47        ));
48
49    let ParseArgs {
50        args: (_, _),              // ("hello", "world")
51        opt_args: (Some(_), None), // (Some(112), None)
52        rest_args: _,              // []
53        meta:
54            (
55                true,
56                _, // SomeType<A, B>
57                None,
58                "conf1_expr",
59                (false, "green_tea"),
60            ),
61    } = parser.parse_attr(&attr).unwrap()
62    else {
63        unreachable!()
64    };
65}
Source

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

Examples found in repository?
examples/test.rs (line 23)
8fn main() {
9    let attr: Attribute = parse_quote! {
10        #[my_attr(
11            "hello",
12            "world",
13            122,
14            conf1 = 114 + 514,
15            key_value = SomeType<A, B>,
16            path_only,
17            nested(tea(green_tea)))
18        ]
19    };
20
21    let parser = ParseArgs::new()
22        .args::<(LitStr, LitStr)>()
23        .opt_args::<(Lit, Lit)>()
24        .rest_args::<Vec<Lit>>()
25        .meta((
26            ("path_only", path_only()),
27            ("key_value", key_value::<Type>()),
28            ("kv_optional", key_value::<Expr>()).optional(),
29            conflicts((
30                ("conf1", path_only()).value("conf1"),
31                ("conf1", key_value::<Expr>()).value("conf1_expr"),
32                ("conf2", key_value::<Expr>()).value("conf2"),
33            )),
34            (
35                "nested",
36                meta_list((
37                    ("milk", path_only()),
38                    (
39                        "tea",
40                        meta_list(conflicts((
41                            ("red_tea", path_only()).value("red_tea"),
42                            ("green_tea", path_only()).value("green_tea"),
43                        ))),
44                    ),
45                )),
46            ),
47        ));
48
49    let ParseArgs {
50        args: (_, _),              // ("hello", "world")
51        opt_args: (Some(_), None), // (Some(112), None)
52        rest_args: _,              // []
53        meta:
54            (
55                true,
56                _, // SomeType<A, B>
57                None,
58                "conf1_expr",
59                (false, "green_tea"),
60            ),
61    } = parser.parse_attr(&attr).unwrap()
62    else {
63        unreachable!()
64    };
65}
Source

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

Examples found in repository?
examples/test.rs (line 24)
8fn main() {
9    let attr: Attribute = parse_quote! {
10        #[my_attr(
11            "hello",
12            "world",
13            122,
14            conf1 = 114 + 514,
15            key_value = SomeType<A, B>,
16            path_only,
17            nested(tea(green_tea)))
18        ]
19    };
20
21    let parser = ParseArgs::new()
22        .args::<(LitStr, LitStr)>()
23        .opt_args::<(Lit, Lit)>()
24        .rest_args::<Vec<Lit>>()
25        .meta((
26            ("path_only", path_only()),
27            ("key_value", key_value::<Type>()),
28            ("kv_optional", key_value::<Expr>()).optional(),
29            conflicts((
30                ("conf1", path_only()).value("conf1"),
31                ("conf1", key_value::<Expr>()).value("conf1_expr"),
32                ("conf2", key_value::<Expr>()).value("conf2"),
33            )),
34            (
35                "nested",
36                meta_list((
37                    ("milk", path_only()),
38                    (
39                        "tea",
40                        meta_list(conflicts((
41                            ("red_tea", path_only()).value("red_tea"),
42                            ("green_tea", path_only()).value("green_tea"),
43                        ))),
44                    ),
45                )),
46            ),
47        ));
48
49    let ParseArgs {
50        args: (_, _),              // ("hello", "world")
51        opt_args: (Some(_), None), // (Some(112), None)
52        rest_args: _,              // []
53        meta:
54            (
55                true,
56                _, // SomeType<A, B>
57                None,
58                "conf1_expr",
59                (false, "green_tea"),
60            ),
61    } = parser.parse_attr(&attr).unwrap()
62    else {
63        unreachable!()
64    };
65}
Source

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

Examples found in repository?
examples/test.rs (lines 25-47)
8fn main() {
9    let attr: Attribute = parse_quote! {
10        #[my_attr(
11            "hello",
12            "world",
13            122,
14            conf1 = 114 + 514,
15            key_value = SomeType<A, B>,
16            path_only,
17            nested(tea(green_tea)))
18        ]
19    };
20
21    let parser = ParseArgs::new()
22        .args::<(LitStr, LitStr)>()
23        .opt_args::<(Lit, Lit)>()
24        .rest_args::<Vec<Lit>>()
25        .meta((
26            ("path_only", path_only()),
27            ("key_value", key_value::<Type>()),
28            ("kv_optional", key_value::<Expr>()).optional(),
29            conflicts((
30                ("conf1", path_only()).value("conf1"),
31                ("conf1", key_value::<Expr>()).value("conf1_expr"),
32                ("conf2", key_value::<Expr>()).value("conf2"),
33            )),
34            (
35                "nested",
36                meta_list((
37                    ("milk", path_only()),
38                    (
39                        "tea",
40                        meta_list(conflicts((
41                            ("red_tea", path_only()).value("red_tea"),
42                            ("green_tea", path_only()).value("green_tea"),
43                        ))),
44                    ),
45                )),
46            ),
47        ));
48
49    let ParseArgs {
50        args: (_, _),              // ("hello", "world")
51        opt_args: (Some(_), None), // (Some(112), None)
52        rest_args: _,              // []
53        meta:
54            (
55                true,
56                _, // SomeType<A, B>
57                None,
58                "conf1_expr",
59                (false, "green_tea"),
60            ),
61    } = parser.parse_attr(&attr).unwrap()
62    else {
63        unreachable!()
64    };
65}

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,

Source§

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_attr(self, input: &Attribute) -> Result<Self::Output>

Source§

fn parse_concat_attrs<'r, I>(self, input: I) -> Result<Self::Output>
where I: Iterator<Item = &'r Attribute>,

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>,

Source§

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>,

Source§

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.