What types this associated type is mapped to?

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"),()))

}
}

! is the never type. It is used as the return type for functions that don’t return, like panic!(). In the context here, it’s a guarantee that the error will never occur.

Thanks. The documentation link is really helpful.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.