Rust standard library implements several smart pointers for better resource cleaned up as they have implemented the 202206221653# 202204061235#. If a reference go out of scope, depending on which kind of smart pointer that it is using, either it will be automatically destroyed or decrements the number of references that is pointing to the referred variable or object. Unlike other programming languages, such rule can be check in compile time if wanted.
All smart pointers have 202206221604# trait implemented so that they could be treated like any other reference type in Rust. Meaning, they can use *
and &
without any significance of syntactic difference from references.
The following shows several smart pointer implementation available in Rust:
- 202206221113#
- 202206221720# that allow multiple ownership of the same object
- 202206232210# where the 202206241126# is checked in runtime instead
- 202206251329# which doesn’t possess variable’s ownership.
Note: Except Rc<T>
, all smart pointers will move the variable which cause a transfer of the ownership.