Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/lib.rs')
-rw-r--r--crates/hir/src/lib.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index db3121d3cd..4938478bb1 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -2756,6 +2756,15 @@ impl Trait {
traits.iter().map(|tr| Trait::from(*tr)).collect()
}
+ pub fn function(self, db: &dyn HirDatabase, name: impl PartialEq<Name>) -> Option<Function> {
+ db.trait_data(self.id).items.iter().find(|(n, _)| name == *n).and_then(
+ |&(_, it)| match it {
+ AssocItemId::FunctionId(id) => Some(Function { id }),
+ _ => None,
+ },
+ )
+ }
+
pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> {
db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect()
}
@@ -4673,6 +4682,10 @@ impl Type {
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Bool))
}
+ pub fn is_str(&self) -> bool {
+ matches!(self.ty.kind(Interner), TyKind::Str)
+ }
+
pub fn is_never(&self) -> bool {
matches!(self.ty.kind(Interner), TyKind::Never)
}