Hacker News new | ask | show | jobs
by masklinn 3026 days ago
> You can't deref a String

You can absolutely deref a String. Not necessarily usefully (or to the satisfaction of the compiler) as it yields an unsized `str` (exactly the same as deref'ing an &str) but you can certainly do it.

    let a = "foo".to_owned();
    let b = &*a;
works perfectly fine.

Incidentally you can also deref' a Vec, that yields a slice (actual sequence, not the commonly seen &[])