Expand description

Declaration Site

License Crates.io Bevy Discord

Implements iterating through the debug info associated with currently loaded objects, to find functions. The main entry point for this crate is for_some_currently_loaded_rust_functions, which internally iterates through all functions which can be found.

This crate was created to be used by bevy, for reporting errors with systems. Other crates making similar use of dependency injection may find this useful. This can be used to get the source code location of a function item type. This is implemented in declaration_by_name and the related functions. However, if searching for multiple names, it will be much more efficient to use for_some_currently_loaded_rust_functions:

let mut expected_names = HashMap::<String, Option<DeclarationSite>>::from([
    // Note that source locations for std/core are less likely to work, this is just an example
    ("std::io::read".into(), None),
    ("std::io::write".into(), None),
for_some_currently_loaded_rust_functions(|name, function| {
    if let Some(result) = expected_names.get_mut(&name) {
        // Note that the `TryFrom` impl is only for `&Function`, so need to add
        // the reference
        *result = DeclarationSite::try_from(&function).ok();
    // We could bail early here if all names have been filled, but that would
    // complicate the example. See the item level documentation for details
// Do things with `expected_names`...


This is a best-effort search only. It may fail to find a given name for any number of reasons:

  • Will not find anything on WASM.
  • If the function is not linked - which may occur if it is never called. it may not be found.
  • The function has been inlined
  • If running on MacOS (we currently silently fail for reasons unknown, and the author cannot debug this due to not having a way to run it. Contributions welcome!)




Some parts of this work (those in src/symbolic_object) are adapted from works licensed only under the MIT license, which can be found in src/symbolic_object/LICENSE. Modifications are also licensed under the terms below. Note that this is the same license as the already existing symbolic-debuginfo dependency.

Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


A source file location, obtained from a symbolic_debuginfo::Function, using TryFrom/TryInto.


An error returned in the TryFrom impl for DeclarationSite.

Control whether iteration over shared libraries should continue or stop.


Attempt to get the declaration site of the function item type of the given type, using its type name. In most cases, you may want to use
declaration_of, since function item types are unnameable.

Attempt to get the declaration site of a currently loaded function with the given (unmangled) name.

Attempt to get the declaration site of the function item type of the given value, using its type name. This is a trivial wrapper around declaration, but may be easier to use since function item types cannot be named.

Run callback on each currently loaded function which can be demangled in the current context, See the caveats section on the module level documentation.