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),
The book has in
Listing 3.7:Rust compiler returns with an error:
Since the
.countreturns ausizeandcourse_idwas defined as anOptionofi32(i.e.Option<i32>):The value for
course_idneeds to be changed to: