aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-20 12:29:15 +0100
committerMartin Fischer <martin@push-f.com>2021-11-20 12:29:28 +0100
commite918eb0ab2cf6d84751f5f52b49414d382b7abbb (patch)
tree0838bf246c8b8676985ecbdc6255b21fe619e12a /src
parent7d549f29d63df264884e80f1e95d881d7c0f7407 (diff)
refactor: remove now pointless internal trait
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs36
-rw-r--r--src/transform.rs26
2 files changed, 15 insertions, 47 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 957d424..21efe52 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -400,42 +400,6 @@ impl TypeTransform {
}
}
-/// Just a convenience trait for us to avoid match/if-let blocks everywhere.
-trait As<T> {
- fn get_as(&self) -> Option<&T>;
- fn get_as_mut(&mut self) -> Option<&mut T>;
-}
-
-impl As<AngleBracketedGenericArguments> for PathArguments {
- fn get_as(&self) -> Option<&AngleBracketedGenericArguments> {
- match self {
- PathArguments::AngleBracketed(args) => Some(args),
- _other => None,
- }
- }
- fn get_as_mut(&mut self) -> Option<&mut AngleBracketedGenericArguments> {
- match self {
- PathArguments::AngleBracketed(args) => Some(args),
- _other => None,
- }
- }
-}
-
-impl As<Type> for GenericArgument {
- fn get_as(&self) -> Option<&Type> {
- match self {
- GenericArgument::Type(typearg) => Some(typearg),
- _other => None,
- }
- }
- fn get_as_mut(&mut self) -> Option<&mut Type> {
- match self {
- GenericArgument::Type(typearg) => Some(typearg),
- _other => None,
- }
- }
-}
-
fn path_segment_for_trait(sometrait: &ItemTrait) -> PathSegment {
PathSegment {
ident: sometrait.ident.clone(),
diff --git a/src/transform.rs b/src/transform.rs
index cbada94..c3116cf 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -1,13 +1,16 @@
use std::collections::HashMap;
use proc_macro2::Span;
-use syn::{spanned::Spanned, Generics, Ident, PathArguments, Type, TypeParamBound, TypePath};
+use syn::{
+ spanned::Spanned, GenericArgument, Generics, Ident, PathArguments, Type, TypeParamBound,
+ TypePath,
+};
use crate::{
parse_assoc_type::DestType,
parse_trait_sig::{MethodParseError, TypeTransform},
syn_utils::{find_in_path, find_in_type},
- As, AssocTypeMatcher,
+ AssocTypeMatcher,
};
#[derive(Default)]
@@ -42,9 +45,10 @@ impl AssocTypeConversions<'_> {
} else if ident == "Option" && path.segments.len() == 1 {
let first_seg = path.segments.first_mut().unwrap();
- if let Some(args) = first_seg.arguments.get_as_mut() {
+ if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
if args.args.len() == 1 {
- if let Some(generic_type) = args.args.first_mut().unwrap().get_as_mut() {
+ if let GenericArgument::Type(generic_type) = args.args.first_mut().unwrap()
+ {
if find_in_type(generic_type, &AssocTypeMatcher).is_some() {
return Ok(TypeTransform::Map(
self.parse_type_path(generic_type)?.into(),
@@ -55,13 +59,12 @@ impl AssocTypeConversions<'_> {
}
} else if ident == "Result" && path.segments.len() == 1 {
let first_seg = path.segments.first_mut().unwrap();
- if let Some(args) = first_seg.arguments.get_as_mut() {
+ if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
if args.args.len() == 2 {
let mut args_iter = args.args.iter_mut();
- if let (Some(ok_type), Some(err_type)) = (
- args_iter.next().unwrap().get_as_mut(),
- args_iter.next().unwrap().get_as_mut(),
- ) {
+ if let (GenericArgument::Type(ok_type), GenericArgument::Type(err_type)) =
+ (args_iter.next().unwrap(), args_iter.next().unwrap())
+ {
if find_in_type(ok_type, &AssocTypeMatcher).is_some()
|| find_in_type(err_type, &AssocTypeMatcher).is_some()
{
@@ -77,9 +80,10 @@ impl AssocTypeConversions<'_> {
let last_seg = &path.segments.last().unwrap();
if last_seg.ident == "Result" {
let last_seg = path.segments.last_mut().unwrap();
- if let Some(args) = last_seg.arguments.get_as_mut() {
+ if let PathArguments::AngleBracketed(args) = &mut last_seg.arguments {
if args.args.len() == 1 {
- if let Some(generic_type) = args.args.first_mut().unwrap().get_as_mut()
+ if let GenericArgument::Type(generic_type) =
+ args.args.first_mut().unwrap()
{
if find_in_type(generic_type, &AssocTypeMatcher).is_some() {
return Ok(TypeTransform::Map(