Search code examples
rusthuggingface

Cannot find def of .has_func or .get_func


I was reading through the code for HuggingFace's candle crate and found two methods whose definitions I couldn't find. The first is .has_func and the second is .get_func.

How can I find the definitions of these methods?

Here's what I have tried:

  • Searching for the string "has_func" in the repo
  • Googling "rust has_func" and checking if any of the results are relevant.
  • Checking if hovering in Github can point me to the def

It raised a more general question in my mind, I wanted to enumerate all the places a method could come from for a struct defined in a given crate, here's what I can think of:

  • The method is defined somewhere in that crate (possibly obscured if defined in a macro)
  • It could be the default definition of a method in a trait that the struct has and the trait is defined in some dependency.
  • Something else? Maybe FFI related?

Solution

  • The best way to find the definition of something is to put it in rust-analyzer. It can almost always do that.

    In this case, it seems to come from cudarc::driver::safe::CudaDevice, which the type Derefs to.