pub fn clone_into_box<T>(ref_dyn: &T) -> Box<T>
Expand description
Clone boxed dyn.
Clones a dynamically sized trait object into a Box< T >
.
ยงExample
use clone_dyn_types::{ CloneDyn, clone_into_box };
#[ derive( Clone ) ]
struct MyStruct
{
value : i32,
}
trait MyTrait : CloneDyn
{
fn val( &self ) -> i32;
}
impl MyTrait for MyStruct
{
fn val( &self ) -> i32
{
self.value
}
}
#[ allow( non_local_definitions ) ]
impl < 'c > Clone
for Box< dyn MyTrait + 'c >
{
#[ inline ]
fn clone( &self ) -> Self { clone_into_box( &**self ) }
}
#[ allow( non_local_definitions ) ]
impl < 'c > Clone
for Box< dyn MyTrait + Send + 'c >
{
#[ inline ]
fn clone( &self ) -> Self { clone_into_box( &**self ) }
}
#[ allow( non_local_definitions ) ]
impl < 'c > Clone
for Box< dyn MyTrait + Sync + 'c >
{
#[ inline ]
fn clone( &self ) -> Self { clone_into_box( &**self ) }
}
#[ allow( non_local_definitions ) ]
impl < 'c > Clone
for Box< dyn MyTrait + Send + Sync + 'c >
{
#[ inline ]
fn clone( &self ) -> Self { clone_into_box( &**self ) }
}
let cloned : Box< dyn MyTrait > = clone_into_box( &MyStruct { value : 42 } );