mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 06:38:03 +08:00
Add a generic map over a graphic's leaves, reaching every depth
This commit is contained in:
@@ -181,10 +181,26 @@ fn element_of(ty: &Type, generics: &[Ident]) -> Element {
|
||||
}
|
||||
match bare_ident(ty) {
|
||||
Some(ident) if generics.contains(ident) => Element::Generic(ident.clone()),
|
||||
_ => Element::Concrete(ty.clone()),
|
||||
_ => match projected_generic(ty, generics) {
|
||||
Some(ident) => Element::Generic(ident),
|
||||
None => Element::Concrete(ty.clone()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// The carried generic an associated type is projected off, as in `V::Mapped<'a>`.
|
||||
/// Such an output is that generic's element re-stated at another lifetime, so it
|
||||
/// rides as the carried element rather than as a freshly written one.
|
||||
fn projected_generic(ty: &Type, generics: &[Ident]) -> Option<Ident> {
|
||||
let Type::Path(path) = ty else { return None };
|
||||
if path.qself.is_some() || path.path.segments.len() < 2 {
|
||||
return None;
|
||||
}
|
||||
let head = &path.path.segments.first()?.ident;
|
||||
|
||||
generics.contains(head).then(|| head.clone())
|
||||
}
|
||||
|
||||
pub(crate) fn strip_ilist(ty: &Type) -> (Type, u8) {
|
||||
let mut element = ty.clone();
|
||||
let mut depth = 0;
|
||||
|
||||
Reference in New Issue
Block a user