[][src]Function tao_of_rust::ch03::type_cast::fqsfd

pub fn fqsfd()

类型转换:as 操作符

Base usage: 无歧义完全限定语法(Fully Qualified Syntax for Disambiguation) 曾用名: 通用函数调用语法(UFCS)

struct S(i32);
trait A {
    fn test(&self, i: i32);
}
trait B {
    fn test(&self, i: i32);
}
impl A for S {
    fn test(&self, i: i32) {
        println!("From A: {:?}", i);
    }
}
impl B for S {
    fn test(&self, i: i32) {
        println!("From B: {:?}", i+1);
    }
}

let s = S(1);
A::test(&s, 1);
B::test(&s, 1);
<S as A>::test(&s, 1);
<S as B>::test(&s, 1);Run

Base usage: 父类型子类型相互转换

let  a: &'static str  = "hello";  // &'static str
let  b: &str = a as &str; // &str
let  c: &'static str = b as &'static str; // &'static strRun