Hey folks, I'm trying to improve the debug visualization of one my crate's types. It is a newtype around str
, very similar to std::path::Path
. I'm hoping someone can point me in the right direction.
I can't seem to find the Natvis definition for std::path::Path
to compare, so I guess it is being generated.
I'm assuming I am either messing up on the resolution (do I need to somehow indicate it being a ref?), the value needs to be cast (ive tried {inner,s}
), or both and maybe more.
The code below can be found in the repro repo: GitHub - chanced/natvis-spike
#![debugger_visualizer(natvis_file = "Spike.natvis")]
#[cfg_attr(not(doc), repr(transparent))]
#[derive(Debug)]
pub struct Spike {
inner: str,
}
impl Spike {
fn new(s: &str) -> &Self {
unsafe { &*(core::ptr::from_ref::<str>(s) as *const Self) }
}
}
fn main() {
let spike = Spike::new("example");
let path = std::path::Path::new("example");
println!("{path:?}\n{spike:?}");
}
<!-- Spike.natvis -->
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="spike::Spike">
<DisplayString>{inner}</DisplayString>
</Type>
</AutoVisualizer>
Which displays as:
Thanks for reading - I greatly appreciate it. I know your time is valuable.