Onelinerhub / onelinerhub

Thousands of code solutions with clear explanation @ onelinerhub.com
https://onelinerhub.com
MIT License
810 stars 161 forks source link

"How to convert pointer to reference in Rust" example code does not compile #2003

Open sudobeans opened 4 months ago

sudobeans commented 4 months ago

The error is with this webpage: https://onelinerhub.com/rust/how-to-convert-pointer-to-reference-in-rust

GitHub link: https://github.com/Onelinerhub/onelinerhub/blob/main//rust/how-to-convert-pointer-to-reference-in-rust.md

It contains this code:

let p: *const i32 = &10;
let r: &i32 = &p;

But this code does not compile because &p is &*const i32. See for yourself on the Rust Playground.

Update: I created PR #2004 to attempt to resolve this