Skip to content

Commit

Permalink
feat/container: prettify parse fn
Browse files Browse the repository at this point in the history
  • Loading branch information
topenkoff committed Jan 28, 2023
1 parent 0dce75f commit 79915ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions hitbox-derive/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ const CACHE_STALE_TTL: &str = "cache_stale_ttl";
const CACHE_VERSION: &str = "cache_version";

fn parse_lit_to_u32(lit: &syn::Lit, attr_name: &str) -> syn::Result<u32> {
let lit = if let syn::Lit::Int(lit) = lit {
Ok(lit)
} else {
Err(syn::Error::new_spanned(
match lit {
syn::Lit::Int(lit) => lit
.base10_parse::<u32>()
.map_err(|e| syn::Error::new_spanned(lit, e)),
_ => Err(syn::Error::new_spanned(
lit,
format!("Expected hitbox {} attribute should be u32", attr_name),
))
}?;

lit.base10_parse::<u32>()
.map_err(|e| syn::Error::new_spanned(lit, e))
)),
}
}

pub struct Container {
Expand All @@ -37,7 +35,6 @@ impl Container {
if !attr.path.is_ident("hitbox") {
return Ok(Vec::new());
}

match attr.parse_meta() {
Ok(syn::Meta::List(meta)) => Ok(meta.nested.into_iter().collect()),
Ok(other) => Err(syn::Error::new_spanned(other, "expected #[hitbox(...)]")),
Expand Down
2 changes: 1 addition & 1 deletion hitbox/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum CachePolicy<T, U> {
NonCacheable(U),
}

/// Thit is one of the basic trait which determines should data store in cache backend or not.
/// This is one of the basic trait which determines should data store in cache backend or not.
///
/// For primitive types and for user-defined types (with derive macro)
/// cache_policy returns CachePolicy::Cached variant.
Expand Down

0 comments on commit 79915ad

Please sign in to comment.