有没有解释为什么评论在第三个例子中被回应?
$ echo a b \
> c # test
a b c
$ echo a b c \
> # test
a b c
$ echo a b c \
> \ # test
a b c # test
$ echo a b c \
> \ # test
a b c
Run Code Online (Sandbox Code Playgroud) 我想在HashMap类型上为包装器类型实现Index trait:
use std::collections::HashMap;
use std::option::Option;
#[cfg(test)]
use std::ops::Index;
#[derive(Debug, Clone)]
struct Value {
val: i32,
}
#[derive(Debug, Clone)]
pub struct HMShadow {
hashmap: HashMap<String, Value>,
}
impl HMShadow {
fn new() -> HMShadow {
HMShadow {
hashmap: {
HashMap::<String, Value>::new()
},
}
}
fn insert<S>(&mut self, key: S, element: Value) -> Option<Value>
where S: Into<String>
{
self.hashmap.insert(key.into(), element)
}
fn get(&mut self, key: &str) -> &mut Value {
self.hashmap.get_mut(key).expect("no entry found for key")
}
}
fn main()
{
let …Run Code Online (Sandbox Code Playgroud)