summaryrefslogtreecommitdiff
path: root/vendor/educe/src/common/bound.rs
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
committermo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
commit8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch)
tree22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/educe/src/common/bound.rs
parent4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff)
chore: add vendor directory
Diffstat (limited to 'vendor/educe/src/common/bound.rs')
-rw-r--r--vendor/educe/src/common/bound.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/educe/src/common/bound.rs b/vendor/educe/src/common/bound.rs
new file mode 100644
index 00000000..78f9aed4
--- /dev/null
+++ b/vendor/educe/src/common/bound.rs
@@ -0,0 +1,57 @@
+use syn::{punctuated::Punctuated, token::Comma, GenericParam, Meta, Path, Type, WherePredicate};
+
+use crate::common::where_predicates_bool::{
+ create_where_predicates_from_all_generic_parameters,
+ create_where_predicates_from_generic_parameters_check_types, meta_2_where_predicates,
+ WherePredicates, WherePredicatesOrBool,
+};
+
+pub(crate) enum Bound {
+ Disabled,
+ Auto,
+ Custom(WherePredicates),
+ All,
+}
+
+impl Bound {
+ #[inline]
+ pub(crate) fn from_meta(meta: &Meta) -> syn::Result<Self> {
+ debug_assert!(meta.path().is_ident("bound"));
+
+ Ok(match meta_2_where_predicates(meta)? {
+ WherePredicatesOrBool::WherePredicates(where_predicates) => {
+ Self::Custom(where_predicates)
+ },
+ WherePredicatesOrBool::Bool(b) => {
+ if b {
+ Self::Auto
+ } else {
+ Self::Disabled
+ }
+ },
+ WherePredicatesOrBool::All => Self::All,
+ })
+ }
+}
+
+impl Bound {
+ #[inline]
+ pub(crate) fn into_where_predicates_by_generic_parameters_check_types(
+ self,
+ params: &Punctuated<GenericParam, Comma>,
+ bound_trait: &Path,
+ types: &[&Type],
+ supertraits: &[proc_macro2::TokenStream],
+ ) -> Punctuated<WherePredicate, Comma> {
+ match self {
+ Self::Disabled => Punctuated::new(),
+ Self::Auto => create_where_predicates_from_generic_parameters_check_types(
+ bound_trait,
+ types,
+ supertraits,
+ ),
+ Self::Custom(where_predicates) => where_predicates,
+ Self::All => create_where_predicates_from_all_generic_parameters(params, bound_trait),
+ }
+ }
+}