#syn #repr #parser #c #parse-attributes #parenthesized

parenthesized_c

A library that allows to parse (C) attribute tokens in #[repr(C)]

1 unstable release

0.1.0 Dec 26, 2021

#2390 in Procedural macros


Used in repr_c_pub_struct

MIT/Apache

7KB

This is a simple library providing ParenthesizedC ZST that implements syn::parse::Parse and thus, for example, can be used with syn::parse2() for the purpose of parsing (C) attribute tokens as in #[repr(C)] outer attribute.

Example:

extern crate syn;
extern crate outer_attribute;
extern crate parenthesized_c;

use parenthesized_c::ParenthesizedC;
use outer_attribute::different_layout::OuterAttribute;

fn main() -> syn::Result<()> {
    let repr_c = syn::parse_str::<OuterAttribute>("#[repr(C)]")?;
    let repr_transpartent = syn::parse_str::<OuterAttribute>("#[repr(transparent)]")?;
    assert!(matches!(syn::parse2::<ParenthesizedC>(repr_c.tokens), Ok(_)));
    assert!(matches!(syn::parse2::<ParenthesizedC>(repr_transpartent.tokens), Err(_)));
    Ok(())
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.5MB
~36K SLoC