のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

expected &{integer}, found integer

assert_eq!(m1.get("b"), Some(&3));
 ✕   assert_eq!(m1.get("b"), Some(3));
 ✕   assert_eq!(m1.get("b"), &3);
 ✕   assert_eq!(m1.get("b"), 3);
 〇   assert_eq!(m1.get("c"), None);
PS > cargo run --example ch05_04_hash_map    
   Compiling ex05 v0.1.0 (\rustbook\ch05\ex05)
error[E0308]: mismatched types                                                                       
  --> examples\ch05_04_hash_map.rs:11:5
   |
11 |      assert_eq!(m1.get("b"), Some(3));
   |     ^^^^^^^^^^^^^^^^^^^^^^ 
   |     expected &{integer}, found integer
   |
   = note: expected type `std::option::Option<&{integer}>`
              found type `std::option::Option<{integer}>`
error[E0308]: mismatched types
  --> examples\ch05_04_hash_map.rs:12:5
   |
12 |     assert_eq!(m1.get("b"), &3);
   |    ^^^^^^^^^^^^^^^^^^^
   |     expected enum `std::option::Option`, found &{integer}
   |     help: try using a variant of the expected type: `Some(*right_val)`
   |
   = note: expected type `std::option::Option<&{integer}>`
              found type `&{integer}`
error[E0308]: mismatched types
  --> examples\ch05_04_hash_map.rs:13:5
   |
13 |     assert_eq!(m1.get("b"), 3);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
   |     expected enum `std::option::Option`, found integer
   |
   = note: expected type `std::option::Option<&{integer}>`
              found type `{integer}`

教科書は、

実践Rust入門[言語仕様から開発手法まで]

実践Rust入門[言語仕様から開発手法まで]