[英]Why is String -> &str different in the impl for Deref and AsRef?
[英]Is there a shorthand for AsRef<T> in Rust?
您可以声明一个特征别名(需要每晚)和/或使用impl trait
trait AsStr = AsRef<str>;
fn my_func(arg: impl AsStr) {
arg.as_ref() ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.