PacktPublishing / Asynchronous-Programming-in-Rust

Asynchronous Programming in Rust, published by Packt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapter 7 is impossible to troubleshoot.

cldershem opened this issue · comments

Because we introduce invalid syntax before we run the corofy tool there is no way to know that our code is correct. Once we run the corofy tool it becomes even more difficult to troubleshoot. There has to be a better way. Maybe corofy can do some kind of cargo check before it does all of it's magic?

I'm doing the book from front to back, typing the code myself...which has led me to finding, troubleshooting, correcting, and reporting many errata....because of that my code isn't exactly the same as the code in your repos. This chapter has a few, smallish problems...but by the time we run corofy it was impossible to follow along. I was finally able to get my code to compile by retyping sections of it. Before retyping...my code had compiled at each step successfully, so there is something wrong somewhere. Once I finish this chapter, if I have time, I will try to retype all the code from start to finish again and see if I can track it down, but I think this chapter could definitely use a closer look.

Hi and thanks for reporting. I'm happy to hear that you're doing the book from front to back typing in the code yourself. That's great. When you come to the chapters where we use corofy I would double check and confirm that the code you end up with is identical to the one in original_main.rs since problems you encounter after running corofy will be hard to debug as you've experienced, for example this for the a-async-await example.

I did write off the code line by line from the book myself one more time to see the errors you encountered. I found a few errors that should be included in the errata (I will report them myself):

Page 143, second code segment should be:
(&str for the path argument and lowercase p in path: path.to_string())

    impl HttpGetFuture {
        fn new(path: &str) -> Self {
            Self {
                stream: None,
                buffer: vec![],
                path: path.to_string(),
            }
        }

Page 148, second code segment should be:
(missing imports of thread and Duration)

    use std::{thread, time::{Duration, Instant}};
    mod future;
    mod http;
    use crate::http::Http;
    use future::{Future, PollState};

But once those are corrected, everything works just as expected when following the steps outlined in the chapter. It would be interesting to see how this compares to the errors you've found and whether you get it working by fixing the errors outlined above or not.

Sorry for these errors in any case, the uppercase P is probably something that happened in the copy-editing stage (one of the last stages), and I remember changing the signature in HttpGetFuture::new so that it aligned with all the other examples, but I must have missed it in the code segment in the book. The missing imports is probably me mixing up the imports of the first example with the two latter examples.

Anyway, thanks for reporting, and I hope that you get it working by correcting the errors above.