![](/img/trans.png)
[英]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.