ion_proc/attribute/
function.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 syn::meta::ParseNestedMeta;
8use syn::{Expr, Result};
9
10use crate::attribute::{ParseArgument as _, ParseAttribute};
11
12#[derive(Default)]
13pub(crate) struct ParameterAttribute {
14	pub(crate) this: bool,
15	pub(crate) convert: Option<Box<Expr>>,
16}
17
18impl ParseAttribute for ParameterAttribute {
19	type Parent<'a> = ();
20
21	fn parse(&mut self, meta: &ParseNestedMeta) -> Result<bool> {
22		let success = self.this.parse_argument(meta, "this", "Parameter")?
23			|| self.convert.parse_argument(meta, "convert", "Parameter")?;
24
25		if self.this && self.convert.is_some() {
26			return Err(meta.error("Parameter with `this` attribute cannot have `convert` attributes."));
27		}
28
29		Ok(success)
30	}
31}