Trait std::borrow::ToOwned1.0.0[][src]

pub trait ToOwned {
    type Owned: Borrow<Self>;
    #[must_use = "cloning is often expensive and is not expected to have side effects"]
    fn to_owned(&self) -> Self::Owned;

    fn clone_into(&self, target: &mut Self::Owned) { ... }
}
Expand description

Clone 到借用数据的一般化。

某些类型通常可以通过实现 Clone trait 从借用变为拥有。 但是 Clone 仅适用于从 &TT 的情况。 ToOwned trait 泛化 Clone 来构造给定类型的任何借用数据。

Associated Types

获得所有权后的结果类型。

Required methods

通常通过克隆从借用数据中创建拥有的数据。

Examples

基本用法:

let s: &str = "a";
let ss: String = s.to_owned();

let v: &[i32] = &[1, 2];
let vv: Vec<i32> = v.to_owned();
Run

Provided methods

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

使用借来的数据来替换拥有的数据,通常是通过克隆。

这是 Clone::clone_from 的借用通用版本。

Examples

基本用法:

let mut s: String = String::new();
"hello".clone_into(&mut s);

let mut v: Vec<i32> = Vec::new();
[1, 2][..].clone_into(&mut v);
Run

Implementors

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added