mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Rollup merge of #85143 - fee1-dead:master, r=Mark-Simulacrum
Document Rc::from
This commit is contained in:
@@ -1733,6 +1733,19 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
||||
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
|
||||
impl<T> From<T> for Rc<T> {
|
||||
/// Converts a generic type `T` into a `Rc<T>`
|
||||
///
|
||||
/// The conversion allocates on the heap and moves `t`
|
||||
/// from the stack into it.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// # use std::rc::Rc;
|
||||
/// let x = 5;
|
||||
/// let rc = Rc::new(5);
|
||||
///
|
||||
/// assert_eq!(Rc::from(x), rc);
|
||||
/// ```
|
||||
fn from(t: T) -> Self {
|
||||
Rc::new(t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user