diesel_derives/deprecated/
changeset_options.rs

1use syn::parse::{ParseStream, Result};
2use syn::{parenthesized, Ident, LitBool};
3
4use crate::deprecated::utils::parse_eq_and_lit_str;
5use crate::util::TREAT_NONE_AS_NULL_NOTE;
6
7pub fn parse_changeset_options(name: Ident, input: ParseStream) -> Result<(Ident, LitBool)> {
8    if input.is_empty() {
9        return Err(syn::Error::new(
10            name.span(),
11            "unexpected end of input, expected parentheses",
12        ));
13    }
14
15    let content;
16    parenthesized!(content in input);
17
18    let name: Ident = content.parse()?;
19    let name_str = name.to_string();
20
21    if name_str != "treat_none_as_null" {
22        return Err(syn::Error::new(
23            name.span(),
24            "expected `treat_none_as_null`",
25        ));
26    }
27
28    Ok((name.clone(), {
29        let lit_str = parse_eq_and_lit_str(name, &content, TREAT_NONE_AS_NULL_NOTE)?;
30        lit_str.parse()?
31    }))
32}