rune_alloc::borrow

Trait TryToOwned

Source
pub trait TryToOwned {
    type Owned: Borrow<Self>;

    // Required method
    fn try_to_owned(&self) -> Result<Self::Owned, Error>;
}
Expand description

A generalization of TryClone to borrowed data.

Some types make it possible to go from borrowed to owned, usually by implementing the TryClone trait. But TryClone works only for going from &T to T. The ToOwned trait generalizes TryClone to construct owned data from any borrow of a given type.

Required Associated Types§

Source

type Owned: Borrow<Self>

The resulting type after obtaining ownership.

Required Methods§

Source

fn try_to_owned(&self) -> Result<Self::Owned, Error>

Creates owned data from borrowed data, usually by cloning.

§Examples

Basic usage:

use rune::alloc::{Vec, String};
use rune::alloc::prelude::*;

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TryToOwned for str

Source§

impl<T> TryToOwned for [T]
where T: TryClone,

Source§

type Owned = Vec<T>

Source§

fn try_to_owned(&self) -> Result<Self::Owned, Error>

Implementors§