use syn::{Attribute, Path};
pub mod field;
pub mod item;
pub mod parsing;
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord)]
pub struct Symbol(pub &'static str, pub &'static str);
pub const BORSH: Symbol = Symbol("borsh", "borsh(...)");
pub const BOUND: Symbol = Symbol("bound", "bound(...)");
pub const USE_DISCRIMINANT: Symbol = Symbol("use_discriminant", "use_discriminant = ...");
pub const SERIALIZE: Symbol = Symbol("serialize", "serialize = ...");
pub const DESERIALIZE: Symbol = Symbol("deserialize", "deserialize = ...");
pub const SKIP: Symbol = Symbol("skip", "skip");
pub const INIT: Symbol = Symbol("init", "init = ...");
pub const SERIALIZE_WITH: Symbol = Symbol("serialize_with", "serialize_with = ...");
pub const DESERIALIZE_WITH: Symbol = Symbol("deserialize_with", "deserialize_with = ...");
pub const CRATE: Symbol = Symbol("crate", "crate = ...");
#[cfg(feature = "schema")]
pub mod schema_keys {
use super::Symbol;
pub const SCHEMA: Symbol = Symbol("schema", "schema(...)");
pub const PARAMS: Symbol = Symbol("params", "params = ...");
pub const WITH_FUNCS: Symbol = Symbol("with_funcs", "with_funcs(...)");
pub const DECLARATION: Symbol = Symbol("declaration", "declaration = ...");
pub const DEFINITIONS: Symbol = Symbol("definitions", "definitions = ...");
}
#[derive(Clone, Copy)]
pub enum BoundType {
Serialize,
Deserialize,
}
impl PartialEq<Symbol> for Path {
fn eq(&self, word: &Symbol) -> bool {
self.is_ident(word.0)
}
}
impl<'a> PartialEq<Symbol> for &'a Path {
fn eq(&self, word: &Symbol) -> bool {
self.is_ident(word.0)
}
}
fn get_one_attribute(attrs: &[Attribute]) -> syn::Result<Option<&Attribute>> {
let count = attrs.iter().filter(|attr| attr.path() == BORSH).count();
let borsh = attrs.iter().find(|attr| attr.path() == BORSH);
if count > 1 {
return Err(syn::Error::new_spanned(
borsh.unwrap(),
format!("multiple `{}` attributes not allowed", BORSH.0),
));
}
Ok(borsh)
}