2022-09-12 20:10:58 +02:00
|
|
|
use crate::attr_parsing::{combine_attribute, parse_parenthesized_attribute, Combine};
|
2022-01-28 10:54:38 +01:00
|
|
|
use syn::{
|
|
|
|
|
parse::{Parse, ParseStream},
|
|
|
|
|
Token,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub(crate) mod kw {
|
|
|
|
|
syn::custom_keyword!(via);
|
2022-08-12 18:05:27 +02:00
|
|
|
syn::custom_keyword!(rejection);
|
2022-09-23 23:50:50 +02:00
|
|
|
syn::custom_keyword!(state);
|
2022-01-28 10:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-12 20:10:58 +02:00
|
|
|
#[derive(Default)]
|
|
|
|
|
pub(super) struct FromRequestContainerAttrs {
|
|
|
|
|
pub(super) via: Option<(kw::via, syn::Path)>,
|
|
|
|
|
pub(super) rejection: Option<(kw::rejection, syn::Path)>,
|
2022-09-23 23:50:50 +02:00
|
|
|
pub(super) state: Option<(kw::state, syn::Type)>,
|
2022-01-28 10:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-12 20:10:58 +02:00
|
|
|
impl Parse for FromRequestContainerAttrs {
|
2024-11-30 16:53:48 +01:00
|
|
|
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
|
2022-09-12 20:10:58 +02:00
|
|
|
let mut via = None;
|
|
|
|
|
let mut rejection = None;
|
2022-09-23 23:50:50 +02:00
|
|
|
let mut state = None;
|
2022-09-12 20:10:58 +02:00
|
|
|
|
|
|
|
|
while !input.is_empty() {
|
|
|
|
|
let lh = input.lookahead1();
|
|
|
|
|
if lh.peek(kw::via) {
|
|
|
|
|
parse_parenthesized_attribute(input, &mut via)?;
|
|
|
|
|
} else if lh.peek(kw::rejection) {
|
|
|
|
|
parse_parenthesized_attribute(input, &mut rejection)?;
|
2022-09-23 23:50:50 +02:00
|
|
|
} else if lh.peek(kw::state) {
|
|
|
|
|
parse_parenthesized_attribute(input, &mut state)?;
|
2022-09-12 20:10:58 +02:00
|
|
|
} else {
|
|
|
|
|
return Err(lh.error());
|
2022-08-12 18:05:27 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-12 20:10:58 +02:00
|
|
|
let _ = input.parse::<Token![,]>();
|
|
|
|
|
}
|
2022-08-12 18:05:27 +02:00
|
|
|
|
2022-09-23 23:50:50 +02:00
|
|
|
Ok(Self {
|
|
|
|
|
via,
|
|
|
|
|
rejection,
|
|
|
|
|
state,
|
|
|
|
|
})
|
2022-05-06 16:53:12 +02:00
|
|
|
}
|
2022-01-28 10:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-12 20:10:58 +02:00
|
|
|
impl Combine for FromRequestContainerAttrs {
|
|
|
|
|
fn combine(mut self, other: Self) -> syn::Result<Self> {
|
2022-09-23 23:50:50 +02:00
|
|
|
let Self {
|
|
|
|
|
via,
|
|
|
|
|
rejection,
|
|
|
|
|
state,
|
|
|
|
|
} = other;
|
2022-09-12 20:10:58 +02:00
|
|
|
combine_attribute(&mut self.via, via)?;
|
|
|
|
|
combine_attribute(&mut self.rejection, rejection)?;
|
2022-09-23 23:50:50 +02:00
|
|
|
combine_attribute(&mut self.state, state)?;
|
2022-09-12 20:10:58 +02:00
|
|
|
Ok(self)
|
|
|
|
|
}
|
2022-01-28 10:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-12 20:10:58 +02:00
|
|
|
#[derive(Default)]
|
|
|
|
|
pub(super) struct FromRequestFieldAttrs {
|
|
|
|
|
pub(super) via: Option<(kw::via, syn::Path)>,
|
2022-01-28 10:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-12 20:10:58 +02:00
|
|
|
impl Parse for FromRequestFieldAttrs {
|
2024-11-30 16:53:48 +01:00
|
|
|
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
|
2022-09-12 20:10:58 +02:00
|
|
|
let mut via = None;
|
|
|
|
|
|
|
|
|
|
while !input.is_empty() {
|
|
|
|
|
let lh = input.lookahead1();
|
|
|
|
|
if lh.peek(kw::via) {
|
|
|
|
|
parse_parenthesized_attribute(input, &mut via)?;
|
|
|
|
|
} else {
|
|
|
|
|
return Err(lh.error());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let _ = input.parse::<Token![,]>();
|
2022-01-28 10:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-12 20:10:58 +02:00
|
|
|
Ok(Self { via })
|
|
|
|
|
}
|
2022-01-28 10:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-12 20:10:58 +02:00
|
|
|
impl Combine for FromRequestFieldAttrs {
|
|
|
|
|
fn combine(mut self, other: Self) -> syn::Result<Self> {
|
|
|
|
|
let Self { via } = other;
|
|
|
|
|
combine_attribute(&mut self.via, via)?;
|
|
|
|
|
Ok(self)
|
2022-01-28 10:54:38 +01:00
|
|
|
}
|
|
|
|
|
}
|