I am trying to learn Rocket and I find when they implement FromRequest trait on a structure data type, they associated type Error to one of the two values ! or (). I understand () to be empty tuple and what does () means. Please help me understand.
Here type Error is associated to !
impl<'a, 'r> FromRequest<'a, 'r> for User {
type Error = !;fn from_request(request: &'a Request<'r>) -> request::Outcome<User, !> { println!("From from_request for User"); request.cookies() .get_private("user_id") .and_then(|cookie| cookie.value().parse().ok()) .map(|id| User(id)) .or_forward(()) }
}
Here type Error is associated to ().
impl<'a, 'r> FromRequest<'a, 'r> for AdminUser {
type Error = ();fn from_request(request: &'a Request<'r>) -> request::Outcome<AdminUser, ()> { let status_not_admin = Status::new(299, "Not an Admin"); println!("From from_request for AdminUser"); let mut conn = request.guard::<db::Conn>().succeeded().unwrap(); let a = request.cookies() .get_private("user_id") .and_then(|cookie| cookie.value().parse().ok()) .and_then(|id : String | db::login::get_role( & mut conn,id).ok()) .map(|id : String | AdminUser(id)); if a.is_some(){ return Success(a.unwrap()) } Failure((Status::new(600, "No"),()))
}
}