小编Har*_*yer的帖子

bash行继续和评论

有没有解释为什么评论在第三个例子中被回应?

$ 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)

bash

6
推荐指数
1
解决办法
393
查看次数

如何在包装好的HashMap上实现索引?

我想在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)

rust

1
推荐指数
1
解决办法
302
查看次数

标签 统计

bash ×1

rust ×1