pub fn replace_containing_crate_name(
    demangled_full_symbol: &str,
    old_crate_name: &str,
    new_crate_name: &str
) -> Option<String>
Expand description

Replaces the old_crate_name substring in the given demangled_full_symbol with the given new_crate_name, if it can be found, and if the parent crate name matches the old_crate_name. If the parent crate name can be found but does not match the expected old_crate_name, then None is returned.

This creates an entirely new String rather than performing an in-place replacement, because the new_crate_name might be a different length than the original crate name.

We cannot simply use str::replace() because it would replace all instances of the old_crate_name, including components of function/symbol names.

Examples

  • replace_containing_crate_name("keyboard::init", "keyboard", "keyboard_new") -> Some("keyboard_new::init")
  • replace_containing_crate_name("<framebuffer::VirtualFramebuffer as display::Display>::fill_rectangle", "display", "display3") -> Some("<framebuffer::VirtualFramebuffer as display3::Display>::fill_rectangle")