Rust 每日一题
给定下面的代码,它是否能够编译通过?
use std::borrow::Borrow;

struct MyString(String);

impl Borrow<str> for MyString {
fn borrow(&self) -> &str {
&self.0
}
}

fn main() {
let s = MyString("Hello".to_string());
let t: &str = s.borrow();
println!("{}", t);
}

A. 能够编译通过
B. 不能编译通过,因为没有实现 BorrowMut trait
C. 不能编译通过,因为没有实现 AsRef trait
D. 不能编译通过,因为没有实现 AsMut trait
展开
3