rustls / rustls-ffi

Use Rustls from any language
Other
132 stars 30 forks source link

Make it easier to inspect a rustls_str #239

Closed kevinburke closed 2 years ago

kevinburke commented 2 years ago

I'm writing a test in Rust that is trying to check a rustls_str, and it's trickier because it's difficult to print the contents of the str to the console.

It might be nice to implement one of

Open to any of these that you think would be best.

jsha commented 2 years ago

Let's give it a #[derive(Debug)]

kevinburke commented 2 years ago

Hmmm... if we add that, I get

rustls_str { data: 0x1027f29b4, len: 4, phantom: PhantomData }

when I try to print using debug formatting:

    #[test]
    fn test_rustls_str_debug() {
        let s = "abcd";
        let rs: rustls_str = s.try_into().unwrap();
        let mut buf = String::new();
        write!(buf, "{:?}", rs);
        println!("{}", buf);
        assert_eq!(3, 4)
    }

So we get some more data, but the contents of the string - what I'm trying to print - I still get out a pointer, which is not great.

jsha commented 2 years ago

Ah, right, sorry - a derived Debug won't work here, you need to implement an actual Debug implementation, which turns the pointer and len into an &str.