#![doc(html_root_url = "https://docs.rs/fieldx_aux/")]
pub mod accessor_helper;
pub mod attributes;
pub mod base_helper;
pub mod builder_helper;
pub mod default_arg;
pub mod doc_arg;
pub mod fallible;
pub mod nesting_attr;
pub mod property;
pub mod serde_helper;
pub mod setter_helper;
pub mod syn_value;
pub mod traits;
#[doc(hidden)]
pub mod util;
pub mod value;
pub mod with_origin;
pub use crate::{
accessor_helper::{FXAccessorHelper, FXAccessorMode},
attributes::FXAttribute,
base_helper::FXBaseHelper,
builder_helper::FXBuilderHelper,
default_arg::FXDefault,
doc_arg::FXDocArg,
fallible::FXFallible,
nesting_attr::{FXNestingAttr, FromNestAttr},
property::*,
serde_helper::FXSerdeHelper,
setter_helper::FXSetterHelper,
syn_value::{FXPunctuated, FXSynTupleArg, FXSynValueArg},
traits::*,
value::FXValueArg,
with_origin::FXOrig,
};
use syn::ext::IdentExt;
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub enum FXSyncMode {
Sync,
Async,
#[default]
Plain,
}
impl syn::parse::Parse for FXSyncMode {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let ident = syn::Ident::parse_any(input)?;
Ok(if ident == "sync" {
Self::Sync
}
else if ident == "async" {
Self::Async
}
else if ident == "plain" {
Self::Plain
}
else {
Err(syn::Error::new_spanned(ident, "expected 'sync', 'async' or 'plain'"))?
})
}
}
impl FXSyncMode {
pub fn is_sync(&self) -> bool {
self == &Self::Sync
}
pub fn is_async(&self) -> bool {
self == &Self::Async
}
pub fn is_plain(&self) -> bool {
self == &Self::Plain
}
pub fn is_true(&self) -> FXProp<bool> {
FXProp::new(true, None)
}
}
pub type FXHelper<const BOOL_ONLY: bool = false> = FXNestingAttr<FXBaseHelper<BOOL_ONLY>>;
pub type FXValue<T, const BOOL_ONLY: bool = false> = FXNestingAttr<FXValueArg<T, BOOL_ONLY>>;
pub type FXSynValue<T, const AS_KEYWORD: bool = false> = FXNestingAttr<FXSynValueArg<T, AS_KEYWORD>, false>;
pub type FXSynTuple<T> = FXNestingAttr<FXSynTupleArg<T>, false>;
pub type FXString = FXNestingAttr<FXValueArg<String>>;
pub type FXBool = FXNestingAttr<FXValueArg<(), true>>;
pub type FXAccessor<const BOOL_ONLY: bool = false> = FXNestingAttr<FXAccessorHelper<BOOL_ONLY>>;
pub type FXSetter<const BOOL_ONLY: bool = false> = FXNestingAttr<FXSetterHelper<BOOL_ONLY>>;
pub type FXBuilder<const STRUCT: bool = false> = FXNestingAttr<FXBuilderHelper<STRUCT>>;
pub type FXSerde = FXNestingAttr<FXSerdeHelper>;
pub type FXDoc = FXNestingAttr<FXDocArg>;
pub type FXAttributes = FXSynValue<FXPunctuated<FXAttribute, syn::Token![,]>>;
#[cfg(test)]
mod tests {
use quote::ToTokens;
use syn::parse_quote;
use super::*;
#[test]
fn fx_attributes() {
let attrs: FXPunctuated<FXAttribute, syn::Token![,]> =
parse_quote! {allow(unused), derive(Debug), serde(rename_all="lowercase")};
assert_eq!(attrs.iter().count(), 3);
let al = attrs
.iter()
.map(|a| a.path().get_ident().to_token_stream().to_string())
.collect::<Vec<_>>();
assert_eq!(al, vec!["allow", "derive", "serde"]);
}
}