Trait call_by::Convert [−][src]
Convert between different calling conventions.
Only some conversions are sensible in Rust, due to the ownership system. These are the valid
conversions, with the constraints on the underlying type T
noted:
Can I convert… | … to Val (T ) | … to Ref (&'a T ) | … to Mut (&'a mut T ) |
---|---|---|---|
from Val (T ) … | (valid for all T ) | ❌* | ❌* |
from Ref (&'a T ) … | T: 'a + Clone | T: 'a | ❌** |
from Mut (&'a mut T ) … | T: 'a + Clone | T: 'a | T: 'a |
* Impossible because references can’t outlive the data they borrow.
** Impossible because potentially-aliased data can’t be mutably referenced.
Required methods
fn convert(from: Self::Type) -> Self::Type
[src]
Convert from one calling convention to another.
Because of the generic parameters on the trait, this often requires rather explicit type annotations.
Examples
use call_by::*; let a: u8 = <u8 as Convert<Val, Val>>::convert(1); let b: u8 = <u8 as Convert<Ref, Val>>::convert(&2); // implicit clone let c: u8 = <u8 as Convert<Mut, Val>>::convert(&mut 3); // implicit clone let d: &u8 = <u8 as Convert<Ref, Ref>>::convert(&4); let e: &u8 = <u8 as Convert<Mut, Ref>>::convert(&mut 5); let b: &mut u8 = <u8 as Convert<Mut, Mut>>::convert(&mut 6);