Expose TyParamBound parsing
diff --git a/src/lib.rs b/src/lib.rs
index f373bf6..e365491 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -132,7 +132,6 @@
unwrap("where clause", generics::parsing::where_clause, input)
}
- #[cfg(feature = "full")]
pub fn parse_token_trees(input: &str) -> Result<Vec<TokenTree>, String> {
unwrap("token trees", mac::parsing::token_trees, input)
}
@@ -141,6 +140,10 @@
unwrap("identifier", ident::parsing::ident, input)
}
+ pub fn parse_ty_param_bound(input: &str) -> Result<TyParamBound, String> {
+ unwrap("type parameter bound", generics::parsing::ty_param_bound, input)
+ }
+
// Deprecated.
#[doc(hidden)]
pub fn parse_macro_input(input: &str) -> Result<MacroInput, String> {
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index c0e21fb..3e2fd42 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -69,3 +69,30 @@
assert_eq!(expected, tokens.to_string());
}
+
+#[test]
+fn test_ty_param_bound() {
+ let tokens = quote!('a);
+ let expected = TyParamBound::Region(Lifetime::new("'a"));
+ assert_eq!(expected, parse_ty_param_bound(tokens.as_str()).unwrap());
+
+ let tokens = quote!(Debug);
+ let expected = TyParamBound::Trait(
+ PolyTraitRef {
+ bound_lifetimes: Vec::new(),
+ trait_ref: "Debug".into(),
+ },
+ TraitBoundModifier::None,
+ );
+ assert_eq!(expected, parse_ty_param_bound(tokens.as_str()).unwrap());
+
+ let tokens = quote!(?Sized);
+ let expected = TyParamBound::Trait(
+ PolyTraitRef {
+ bound_lifetimes: Vec::new(),
+ trait_ref: "Sized".into(),
+ },
+ TraitBoundModifier::Maybe,
+ );
+ assert_eq!(expected, parse_ty_param_bound(tokens.as_str()).unwrap());
+}