Skip to content

Instantly share code, notes, and snippets.

@CarlKCarlK
Created October 19, 2022 21:11
Show Gist options
  • Save CarlKCarlK/6651c8ec5892d663c1e232ba8d15a689 to your computer and use it in GitHub Desktop.
Save CarlKCarlK/6651c8ec5892d663c1e232ba8d15a689 to your computer and use it in GitHub Desktop.
create_maybe_sub_type.rs
fn create_maybe_sub_type(args: &PathArguments, span_range: &SpanRange) -> Option<Type> {
match args {
PathArguments::None => None,
PathArguments::AngleBracketed(ref args) => {
let arg = first_and_only(args.args.iter()).unwrap_or_else(|| {
abort!(span_range, "Expected at exactly one generic parameter.")
});
if let GenericArgument::Type(sub_type2) = arg {
Some(sub_type2.clone())
} else {
abort!(span_range, "Expected generic parameter to be a type.")
}
}
PathArguments::Parenthesized(_) => {
abort!(span_range, "Expected <..> generic parameter.")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment