Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3: Page 72 - Needs "as" #7

Open
krzkrzkrz opened this issue Feb 13, 2024 · 0 comments
Open

Chapter 3: Page 72 - Needs "as" #7

krzkrzkrz opened this issue Feb 13, 2024 · 0 comments

Comments

@krzkrzkrz
Copy link

krzkrzkrz commented Feb 13, 2024

The book has in Listing 3.7:

let new_course = Course {
    tutor_id: new_course.tutor_id,
    course_id: Some(course_count_for_user + 1),
    course_name: new_course.course_name.clone(),
    posted_time: Some(Utc::now().naive_utc()),
};

Rust compiler returns with an error:

course_id: Some(course_count_for_user + 1),
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `usize`

Since the .count returns a usize and course_id was defined as an Option of i32 (i.e. Option<i32>):

let course_count_for_user = app_state
        ...
        .count(); // returns a usize

The value for course_id needs to be changed to:

course_id: Some((course_count_for_user + 1) as i32),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant