code icon indicating copy to clipboard operation
code copied to clipboard

Some little issues find for MEAP v15

Open WindSoilder opened this issue 5 years ago • 5 comments

  • Title of Listing 5.3:

Listing 5.3. Inspecting a float’s bit string by interpreting its bits as an integer (ch1-f32-as-u32.rs)**

Is it should be: Listing 5.3. Inspecting a float’s bit string by interpreting its bits as an integer (ch5-f32-as-u32.rs) ?

  • the bottom of P133:

To print a value a individual bits, the type of that value must implement fmt::Display. f32 doesn’t implement fmt::Binary

Is it should be: To print a value a individual bits, the type of that value must implement fmt::Binary. f32 doesn’t implement fmt::Binary?

  • Title of Listing 5.6:

Listing 5.6. Impossible Addition (ch1/ch1-impossible-addition.rs)

Is it should be: Listing 5.6. Impossible Addition (ch5/ch5-impossible-addition.rs)

Addition to listing 5.6, rustc can caught such error.(I'm running rustc 1.49.0). It tells me such error message:

error: this arithmetic operation will overflow
 --> src\bin\ch5-to-oblivion.rs:3:17
  |
3 |     let c: u8 = a + b;
  |                 ^^^^^ attempt to compute `200_u8 + 200_u8`, which would overflow
  |
  = note: `#[deny(arithmetic_overflow)]` on by default

rustc is more powerful now :-)

  • Listing 5.7. Inspecting Endianness (ch1-endianness.rs)

Is it should be: Listing 5.7. Inspecting Endianness (ch5-endianness.rs)

Hope it can help... Maybe I can find something more, and I will update here :-)

WindSoilder avatar Jan 09 '21 12:01 WindSoilder

The same as #8 , I'm also find that the code is missing

WindSoilder avatar Feb 03 '21 04:02 WindSoilder

Thank you very much for these corrections. I hope that you have enjoyed the chapter, regardless of those issues.

Which version of the MEAP are you reading, by the way @WindSoilder ? Version 15 is the most recent.

timClicks avatar Feb 03 '21 08:02 timClicks

You're welcome :-) I'm reading Version 15

WindSoilder avatar Feb 03 '21 21:02 WindSoilder

Code for Listing6.4,

    println!("c (a "box" for C):");   //  This should be println!("c (a \"box\" for C):");
    println!("  location:  {:p}", &c);
    println!("  size:      {:?} bytes", size_of::<Box<[u8]>>());
    println!("  points to: {:p}", c);
    println!();

WindSoilder avatar Feb 07 '21 21:02 WindSoilder

Code for Listing7.28,

match action {
    "get" => {
        let index_as_bytes = a.get(&INDEX_KEY).unwrap().unwrap();
        let index: HashMap<ByteString, u64> = bincode::deserialize(&index_as_bytes).unwrap();
        match index.get(key) {
            None => eprintln!("{:?} not found", key),
            // NOTE: error here? because the `value` is just the offset of database file...
            Some(value) => println!("{:?}", value), // needs to use Debug as [u8] is arbitrary bytes.     
     },
    ....
},

I think it should be something like:

    match action {
        "get" => {
            let index_as_bytes = a.get(INDEX_KEY).unwrap().unwrap();
            let index: HashMap<ByteString, u64> = bincode::deserialize(&index_as_bytes).unwrap();

            match index.get(key) {
                None => eprintln!("{:?} not found", key),
                Some(idx) => {
                    let kv = a.get_at(*idx).unwrap();
                    println!("{:?}", kv.value);
                }
            }
        },
    ....
},

WindSoilder avatar Feb 15 '21 02:02 WindSoilder