小编Kev*_*ose的帖子

Rust HashMap:为什么我需要双“&”号?

我在参考锈方面遇到了麻烦。我有以下无法编译的代码:

use std::collections::HashMap;

fn main() {
    let mut map = HashMap::new();

    map.insert(&0, &0);
    map.insert(&1, &1);

    assert_eq!(map.get(&0), Some(&0));
}
Run Code Online (Sandbox Code Playgroud)

我得到的编译错误是:

error[E0308]: mismatched types
 --> rust_doubt.rs:9:5
  |
9 |     assert_eq!(map.get(&0), Some(&0));
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &{integer}, found integral variable
  |
  = note: expected type `std::option::Option<&&{integer}>`
             found type `std::option::Option<&{integer}>`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error
Run Code Online (Sandbox Code Playgroud)

果然,如果我改变这一行:

assert_eq!(map.get(&0), Some(&0));assert_eq!(map.get(&0), Some(&&0)); …

rust

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

浏览器如何渲染canvas元素的内容

浏览器如何渲染html画布的内容?像 context.lineTo(x, y) 这样的东西。必须有某个组件将所有函数调用转换为像素数据。我真正想知道的是是否有某种方法可以获取这些像素数据而不需要实际将其渲染到某个地方。

我想知道我们是否可以运行某种独立的 JavaScript 引擎(v8)并将 JavaScript 代码传递给它并获取像素数据作为输出。

html javascript html5-canvas web

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

标签 统计

html ×1

html5-canvas ×1

javascript ×1

rust ×1

web ×1