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()?;

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TryToOwned for str

source§

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

Implementors§