ion_proc/attribute/
krate.rs

1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 */
6
7use proc_macro2::TokenStream;
8use syn::meta::ParseNestedMeta;
9use syn::{Attribute, Result, parse_quote};
10
11use crate::attribute::{ParseArgument as _, ParseAttribute};
12
13#[derive(Default)]
14struct CrateAttribute {
15	krate: Option<TokenStream>,
16}
17
18impl ParseAttribute for CrateAttribute {
19	type Parent<'a> = ();
20
21	fn parse(&mut self, meta: &ParseNestedMeta) -> Result<bool> {
22		self.krate.parse_argument(meta, "crate", "Attribute")
23	}
24}
25
26pub(crate) fn crate_from_attributes(attrs: &mut Vec<Attribute>) -> TokenStream {
27	let attribute = CrateAttribute::from_attributes("ion", attrs, ()).unwrap();
28	attribute.krate.unwrap_or_else(|| parse_quote!(::ion))
29}