Skip to content

Commit

Permalink
Styling: format all sources
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Nov 26, 2024
1 parent 6dfbd4a commit c3b4382
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 74 deletions.
4 changes: 2 additions & 2 deletions fieldx_aux/src/fallible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct FXFallible<T = FXSynValue<syn::Path>>
where
T: FromMeta,
{
off: Flag,
off: Flag,
#[darling(rename = "error")]
error_type: Option<T>,
// error_type: Option<FXSynValue<syn::Path>>,
Expand Down Expand Up @@ -37,7 +37,7 @@ where
{
fn for_keyword(_path: &syn::Path) -> darling::Result<Self> {
Ok(Self {
off: Flag::default(),
off: Flag::default(),
error_type: None,
})
}
Expand Down
57 changes: 38 additions & 19 deletions fieldx_derive/src/codegen/codegen_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ pub trait FXCodeGenContextual {

if generic_idents.len() > 0 {
quote![< #( #generic_idents ),* >]
} else {
}
else {
quote![]
}
}
Expand All @@ -239,11 +240,13 @@ pub trait FXCodeGenContextual {
let post_constuct = if let Some(init) = init {
let shortcut = if ctx.build_has_error_type() {
quote![?]
} else {
}
else {
quote![]
};
quote![.#init() #shortcut]
} else {
}
else {
quote![]
};

Expand All @@ -261,7 +264,8 @@ pub trait FXCodeGenContextual {
}
)
]
} else {
}
else {
quote![
#self_name {
#struct_init
Expand All @@ -274,7 +278,8 @@ pub trait FXCodeGenContextual {
fn maybe_optional<TT: ToTokens>(&self, fctx: &FXFieldCtx, ty: TT) -> TokenStream {
if fctx.is_optional() {
quote![::std::option::Option<#ty>]
} else {
}
else {
ty.to_token_stream()
}
}
Expand Down Expand Up @@ -336,12 +341,15 @@ pub trait FXCodeGenContextual {

FXValueRepr::Versatile(if is_str {
quote_spanned! [span=> ::std::string::String::from(#def_meta) ]
} else {
}
else {
quote_spanned! [span=> #def_meta ]
})
} else if fctx.is_lazy() || fctx.is_optional() {
}
else if fctx.is_lazy() || fctx.is_optional() {
FXValueRepr::None
} else {
}
else {
FXValueRepr::Exact(quote_spanned! [field.span()=> ::std::default::Default::default() ])
}
}
Expand All @@ -363,7 +371,8 @@ pub trait FXCodeGenContextual {
self
}
])
} else {
}
else {
Ok(quote![])
}
}
Expand All @@ -377,7 +386,8 @@ pub trait FXCodeGenContextual {
// of the builder like, for example, when they may refer to generic lifetimes.
let allow_attr = if !fctx.forced_builder() && !fctx.needs_builder() {
quote![#[allow(dead_code)]]
} else {
}
else {
quote![]
};
Ok(quote_spanned![span=> #attributes #allow_attr #ident: ::std::option::Option<#ty>])
Expand All @@ -394,15 +404,17 @@ pub trait FXCodeGenContextual {
let field_set_error = if let Some(variant) = ctx.builder_error_variant() {
// If variant is explicitly specified then use it.
quote_spanned! {span=> #variant(#field_name.into())}
} else if ctx.builder_error_type().is_some() {
}
else if ctx.builder_error_type().is_some() {
// If there is no variant but custom error type is requested then we expect that custom type to
// implement From<FieldXError> trait.
quote_spanned! {span=>
::std::convert::Into::into(
::fieldx::error::FieldXError::uninitialized_field(#field_name.into())
)
}
} else {
}
else {
quote_spanned! {span =>
::fieldx::error::FieldXError::uninitialized_field(#field_name.into())
}
Expand All @@ -425,7 +437,8 @@ pub trait FXCodeGenContextual {
},
|tt| Some(tt),
)
} else if fctx.is_optional() && !fctx.is_builder_required() {
}
else if fctx.is_optional() && !fctx.is_builder_required() {
self.field_value_wrap(
fctx,
FXValueRepr::Exact(quote_spanned![*span=> ::std::option::Option::None]),
Expand All @@ -437,7 +450,8 @@ pub trait FXCodeGenContextual {
},
|tt| Some(tt),
)
} else {
}
else {
None
};

Expand All @@ -454,7 +468,8 @@ pub trait FXCodeGenContextual {
#alternative
}
]
} else {
}
else {
// If no alternative init path provided then we just unwrap. It'd be either totally safe if builder checker
// is set for this field, or won't be ever run because of an earlier error in this method.
let value_wrapped = self.ok_or_empty(
Expand All @@ -476,7 +491,8 @@ pub trait FXCodeGenContextual {
TokenTree::Ident(ref ident) => {
if ident.to_string() == "Self" {
fixed_tokens.extend(quote![<#struct_ident #generics>]);
} else {
}
else {
fixed_tokens.extend(t.to_token_stream());
}
}
Expand All @@ -503,7 +519,8 @@ pub trait FXCodeGenContextual {
quote![FXVALINTO],
quote![.into()],
)
} else {
}
else {
(quote![], quote![#ty], quote![])
}
}
Expand All @@ -524,7 +541,8 @@ pub trait FXCodeGenContextual {
// Unwrap must be safe here because if the object has been legally reached out by user code then
// it means there is at least one Arc instance alive and thus the strong count is > 0
quote![self.#myself_method().expect(#expect_msg)]
} else {
}
else {
quote![self]
}
}
Expand All @@ -546,7 +564,8 @@ pub trait FXCodeGenContextual {
let error_type = fctx.fallible_error()?;
let span = fctx.fallible_span();
quote_spanned! {span=> ::std::result::Result<#ty, #error_type>}
} else {
}
else {
quote![#ty]
})
}
Expand Down
8 changes: 4 additions & 4 deletions fieldx_derive/src/ctx/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,13 @@ impl FXFieldCtx {
self.get_helper_span(FXHelperKind::Clearer)
.or_else(|| self.get_helper_span(FXHelperKind::Predicate))
},
|o| o.span(),
|o| o.orig_span(),
)
.unwrap_or_else(|| Span::call_site())
}

pub fn lock_span(&self) -> Span {
self.lock().and_then(|l| l.span()).unwrap_or_else(|| {
self.lock().and_then(|l| l.orig_span()).unwrap_or_else(|| {
self.get_helper_span(FXHelperKind::Reader)
.or_else(|| self.get_helper_span(FXHelperKind::Writer))
.unwrap_or_else(|| self.optional_span())
Expand All @@ -421,7 +421,7 @@ impl FXFieldCtx {

pub fn inner_mut_span(&self) -> Span {
self.inner_mut()
.and_then(|im| im.span())
.and_then(|im| im.orig_span())
.unwrap_or_else(|| Span::call_site())
}

Expand All @@ -442,7 +442,7 @@ impl FXFieldCtx {
.fallible()
.as_ref()
.or_else(|| self.codegen_ctx().args().fallible().as_ref())
.and_then(|f| f.span())
.and_then(|f| f.orig_span())
.unwrap_or_else(|| self.span().clone())
}

Expand Down
4 changes: 2 additions & 2 deletions fieldx_derive/src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ impl FXFieldReceiver {
.or_else(|| {
self.copy
.as_ref()
.and_then(|c| (c as &dyn fieldx_aux::FXOrig<_>).span())
.and_then(|c| (c as &dyn fieldx_aux::FXOrig<_>).orig_span())
})
.or_else(|| {
self.clone
.as_ref()
.and_then(|c| (c as &dyn fieldx_aux::FXOrig<_>).span())
.and_then(|c| (c as &dyn fieldx_aux::FXOrig<_>).orig_span())
})
}

Expand Down
72 changes: 37 additions & 35 deletions fieldx_derive/src/util/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,49 @@ use proc_macro2::Span;
#[getset(get = "pub")]
pub(crate) struct FXSArgs {
#[getset(skip)]
mode: Option<FXSynValue<FXSyncMode>>,
mode: Option<FXSynValue<FXSyncMode>>,
#[getset(skip)]
#[darling(rename = "sync")]
mode_sync: Option<FXBoolArg>,
mode_sync: Option<FXBoolArg>,
#[getset(skip)]
#[darling(rename = "r#async")]
mode_async: Option<FXBoolArg>,

builder: Option<FXBuilder<true>>,
into: Option<FXBoolArg>,
into: Option<FXBoolArg>,

no_new: Option<FXBoolArg>,
no_new: Option<FXBoolArg>,
default: Option<FXBoolArg>,
// Produce reference counted object; i.e. Rc<Self> or Arc<Self>.
rc: Option<FXHelper>,
rc: Option<FXHelper>,

attributes: Option<FXAttributes>,
attributes: Option<FXAttributes>,
attributes_impl: Option<FXAttributes>,

// Field defaults
fallible: Option<FXNestingAttr<FXFallible>>,
lazy: Option<FXHelper>,
fallible: Option<FXNestingAttr<FXFallible>>,
lazy: Option<FXHelper>,
#[darling(rename = "get")]
accessor: Option<FXAccessor>,
accessor: Option<FXAccessor>,
#[darling(rename = "get_mut")]
accessor_mut: Option<FXHelper>,
#[darling(rename = "set")]
setter: Option<FXSetter>,
reader: Option<FXHelper>,
writer: Option<FXHelper>,
clearer: Option<FXHelper>,
predicate: Option<FXHelper>,
optional: Option<FXBoolArg>,
public: Option<FXNestingAttr<FXPubMode>>,
private: Option<FXBoolArg>,
setter: Option<FXSetter>,
reader: Option<FXHelper>,
writer: Option<FXHelper>,
clearer: Option<FXHelper>,
predicate: Option<FXHelper>,
optional: Option<FXBoolArg>,
public: Option<FXNestingAttr<FXPubMode>>,
private: Option<FXBoolArg>,
#[getset(get = "pub with_prefix")]
clone: Option<FXBoolArg>,
clone: Option<FXBoolArg>,
#[getset(get = "pub with_prefix")]
copy: Option<FXBoolArg>,
lock: Option<FXBoolArg>,
inner_mut: Option<FXBoolArg>,
copy: Option<FXBoolArg>,
lock: Option<FXBoolArg>,
inner_mut: Option<FXBoolArg>,
#[cfg(feature = "serde")]
serde: Option<FXSerde>,
serde: Option<FXSerde>,
}

impl FXSArgs {
Expand Down Expand Up @@ -132,7 +132,8 @@ impl FXSArgs {
if self.clone.is_true() {
// Explicitly set `clone` means "not copy"
Some(false)
} else {
}
else {
self.copy.is_true_opt()
}
}
Expand All @@ -142,7 +143,8 @@ impl FXSArgs {
if self.copy.is_true() {
// Explicitly set `clone` means "not copy"
Some(false)
} else {
}
else {
self.clone.is_true_opt()
}
}
Expand Down Expand Up @@ -264,12 +266,12 @@ impl FXSArgs {
.or_else(|| {
self.copy
.as_ref()
.and_then(|c| (c as &dyn fieldx_aux::FXOrig<_>).span())
.and_then(|c| (c as &dyn fieldx_aux::FXOrig<_>).orig_span())
})
.or_else(|| {
self.clone
.as_ref()
.and_then(|c| (c as &dyn fieldx_aux::FXOrig<_>).span())
.and_then(|c| (c as &dyn fieldx_aux::FXOrig<_>).orig_span())
})
}

Expand All @@ -296,15 +298,15 @@ impl FXHelperContainer for FXSArgs {

fn get_helper_span(&self, kind: FXHelperKind) -> Option<Span> {
match kind {
FXHelperKind::Accessor => self.accessor().as_ref().and_then(|h| h.span()),
FXHelperKind::AccessorMut => self.accessor_mut().as_ref().and_then(|h| h.span()),
FXHelperKind::Builder => self.builder().as_ref().and_then(|h| h.span()),
FXHelperKind::Clearer => self.clearer().as_ref().and_then(|h| h.span()),
FXHelperKind::Lazy => self.lazy().as_ref().and_then(|h| h.span()),
FXHelperKind::Predicate => self.predicate().as_ref().and_then(|h| h.span()),
FXHelperKind::Reader => self.reader().as_ref().and_then(|h| h.span()),
FXHelperKind::Setter => self.setter().as_ref().and_then(|h| h.span()),
FXHelperKind::Writer => self.writer().as_ref().and_then(|h| h.span()),
FXHelperKind::Accessor => self.accessor().as_ref().and_then(|h| h.orig_span()),
FXHelperKind::AccessorMut => self.accessor_mut().as_ref().and_then(|h| h.orig_span()),
FXHelperKind::Builder => self.builder().as_ref().and_then(|h| h.orig_span()),
FXHelperKind::Clearer => self.clearer().as_ref().and_then(|h| h.orig_span()),
FXHelperKind::Lazy => self.lazy().as_ref().and_then(|h| h.orig_span()),
FXHelperKind::Predicate => self.predicate().as_ref().and_then(|h| h.orig_span()),
FXHelperKind::Reader => self.reader().as_ref().and_then(|h| h.orig_span()),
FXHelperKind::Setter => self.setter().as_ref().and_then(|h| h.orig_span()),
FXHelperKind::Writer => self.writer().as_ref().and_then(|h| h.orig_span()),
}
}
}
Loading

0 comments on commit c3b4382

Please sign in to comment.