Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14336 - swarnimarun:remove-slice, r=lnicola
internal: add `as_slice` to `hir::Type`
~`remove_slice`~ `as_slice` is same as `remove_ref` but for slices.
Though there is `as_array` which I believe was named such because it also gets the length of the array, maybe. I am still shaky on the names feel free to suggest corrections.
| -rw-r--r-- | crates/hir/src/lib.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 6d0083c071..27c4577d60 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -3232,6 +3232,13 @@ impl Type { } } + pub fn as_slice(&self) -> Option<Type> { + match &self.ty.kind(Interner) { + TyKind::Slice(ty) => Some(self.derived(ty.clone())), + _ => None, + } + } + pub fn strip_references(&self) -> Type { self.derived(self.ty.strip_references().clone()) } |