#![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;
pub use crate::accessor_helper::FXAccessorMode;
pub use crate::attributes::FXAttribute;
pub use crate::base_helper::FXBaseHelper;
pub use crate::builder_helper::FXBuilderHelper;
pub use crate::default_arg::FXDefault;
pub use crate::doc_arg::FXDocArg;
pub use crate::fallible::FXFallible;
pub use crate::nesting_attr::FXNestingAttr;
pub use crate::nesting_attr::FromNestAttr;
pub use crate::property::*;
pub use crate::serde_helper::FXSerdeHelper;
pub use crate::setter_helper::FXSetterHelper;
pub use crate::syn_value::FXPunctuated;
pub use crate::syn_value::FXSynTupleArg;
pub use crate::syn_value::FXSynValueArg;
pub use crate::traits::*;
pub use crate::value::FXValueArg;
pub use crate::with_origin::FXOrig;
pub use fieldx_derive_support::fxhelper;
use syn::ext::IdentExt;
use value::FXEmpty;
#[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<FXEmpty, 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"]);
}
}