January 2019
Intermediate to advanced
520 pages
14h 32m
English
To modify a specific user, we need their identifier. REST specifies that you need to get the IDs from a path, because REST maps data entities to URLs.
We can extract a user's identifier using the tail of the path, which we already have. This is why we use the starts_with method of the string, instead of checking for strong equality with USER_PATH to the path tails.
We previously declared the UserId type, which equals the u64 unsigned number. Add this code to the second branch of the previously-declared match expression with the (method, path) pattern to extract the user's identifier from the path:
let user_id = path.trim_left_matches(USER_PATH) .parse::<UserId>() .ok() .map(|x| x as usize);
The str::trim_left_matches ...
Read now
Unlock full access