Content deleted Content added
+cat. |
→Pointers: Please stop adding this, it is already covered to an appropriate level of detail literally in the following sentence. |
||
Line 665:
|}
To prevent the use of [[null pointer]]s and their [[Null pointer#Null dereferencing|dereferencing]], the basic <code>&</code> and <code>&mut</code> references are guaranteed to not be null. Rust instead uses <code>Option</code> for this purpose: <code>Some(T)</code> indicates that a value is present, and <code>None</code> is analogous to the null pointer.{{sfn|Klabnik|Nichols|2019|pp=101–104}} <code>Option</code> implements a "null pointer optimization", avoiding any spatial overhead for types that cannot have a null value (references or the <code>NonZero</code> types, for example).<ref>{{Cite web |title=std::option |url=https://doc.rust-lang.org/std/option/index.html#representation |access-date=2023-11-12 |website=The Rust Standard Library documentation}}</ref>
Rust also supports raw pointer types <code>*const</code> and <code>*mut</code>, which may be null; however, it is impossible to dereference them unless the code is explicitly declared unsafe through the use of an <code>unsafe</code> block. Unlike dereferencing, the creation of raw pointers is allowed inside of safe Rust code.{{sfn|Klabnik|Nichols|2019|pp=418–427}}
|