aboutsummaryrefslogtreecommitdiff
path: root/syrette_macros/src/libs/intertrait_macros/args.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-07-18 20:48:41 +0200
committerHampusM <hampus@hampusmat.com>2022-07-18 20:49:33 +0200
commit8976c166cff4c98c43cdc409275f548eb27ecb13 (patch)
treef072980e77e12a85aac7282b89d3114cf69864a7 /syrette_macros/src/libs/intertrait_macros/args.rs
parent51e8d04c2299e6468213d8ee4f9e15d783094379 (diff)
refactor: reduce the capabilities of the castable_to macro
Diffstat (limited to 'syrette_macros/src/libs/intertrait_macros/args.rs')
-rw-r--r--syrette_macros/src/libs/intertrait_macros/args.rs77
1 files changed, 7 insertions, 70 deletions
diff --git a/syrette_macros/src/libs/intertrait_macros/args.rs b/syrette_macros/src/libs/intertrait_macros/args.rs
index d576ae2..a49567f 100644
--- a/syrette_macros/src/libs/intertrait_macros/args.rs
+++ b/syrette_macros/src/libs/intertrait_macros/args.rs
@@ -11,89 +11,26 @@
* at your option.
*/
-use std::collections::HashSet;
-
-use syn::bracketed;
use syn::parse::{Parse, ParseStream, Result};
-use syn::punctuated::Punctuated;
-use syn::{Error, Ident, Path, Token, Type};
-
-#[derive(Hash, PartialEq, Eq)]
-pub enum Flag
-{
- Sync,
-}
-
-impl Flag
-{
- fn from(ident: &Ident) -> Result<Self>
- {
- match ident.to_string().as_str() {
- "sync" => Ok(Flag::Sync),
- unknown => {
- let msg = format!("Unknown flag: {}", unknown);
- Err(Error::new_spanned(ident, msg))
- }
- }
- }
-}
-
-pub struct Targets
-{
- pub flags: HashSet<Flag>,
- pub paths: Vec<Path>,
-}
+use syn::{Path, Token, Type};
-impl Parse for Targets
-{
- fn parse(input: ParseStream) -> Result<Self>
- {
- let mut flags = HashSet::new();
- let mut paths = Vec::new();
-
- if input.is_empty() {
- return Ok(Targets { flags, paths });
- }
-
- if input.peek(syn::token::Bracket) {
- let content;
- bracketed!(content in input);
- for ident in Punctuated::<Ident, Token![,]>::parse_terminated(&content)? {
- if !flags.insert(Flag::from(&ident)?) {
- let msg = format!("Duplicated flag: {}", ident);
- return Err(Error::new_spanned(ident, msg));
- }
- }
- }
-
- if input.is_empty() {
- return Ok(Targets { flags, paths });
- }
-
- paths = Punctuated::<Path, Token![,]>::parse_terminated(input)?
- .into_iter()
- .collect();
-
- Ok(Targets { flags, paths })
- }
-}
-
-pub struct Casts
+pub struct Cast
{
pub ty: Type,
- pub targets: Targets,
+ pub target: Path,
}
-impl Parse for Casts
+impl Parse for Cast
{
fn parse(input: ParseStream) -> Result<Self>
{
let ty: Type = input.parse()?;
+
input.parse::<Token![=>]>()?;
- Ok(Casts {
+ Ok(Cast {
ty,
- targets: input.parse()?,
+ target: input.parse()?,
})
}
}