fn handler(state: State) -> (State, Response) {
    // Define a narrow scope so that state can be borrowed/moved later in the function.
    let adjective_from_cookie = {
        // Get the request headers.
        let headers: &Headers = Headers::borrow_from(&state);
        // Get the Cookie header from the request.
        let maybe_cookie = headers.get::<Cookie>();
        // Get the value of the "adjective" cookie, if set.
        maybe_cookie.and_then(|cookie| cookie.get("adjective").map(|s| s.to_owned()))
    };

    let adjective = adjective_from_cookie.unwrap_or("first time".to_owned());

    let mut response = {
        create_response(
            &state,
            StatusCode::Ok,
            Some((
                format!("Hello {} visitor\n", adjective).as_bytes().to_vec(),
                mime::TEXT_PLAIN,
            )),
        )
    };
    {
        // Make a new cookie. This is currently one of the less type-safe corners of Gotham.
        let cookie = "adjective=repeat; HttpOnly".to_owned();
        set_cookie(cookie, &mut response);
    }
    (state, response)
}
/// The first request will set a cookie, and subsequent requests will echo it back.
The first request will set a cookie, and subsequent requests will echo it back.
The first request will set a cookie and subsequent requests will echo it back .
fn handler(state: State) -> (State, Response) {
    // Define a narrow scope so that state can be borrowed/moved later in the function.
    let adjective_from_cookie = {
        // Get the request headers.
        let headers: &Headers = Headers::borrow_from(&state);
        // Get the Cookie header from the request.
        let maybe_cookie = headers.get::<Cookie>();
        // Get the value of the "adjective" cookie, if set.
        maybe_cookie.and_then(|cookie| cookie.get("adjective").map(|s| s.to_owned()))
    };
    let adjective = adjective_from_cookie.unwrap_or("first time".to_owned());
    let mut response = {
        create_response(
            &state,
            StatusCode::Ok,
            Some((
                format!("Hello {} visitor\n", adjective).as_bytes().to_vec(),
                mime::TEXT_PLAIN,
            )),
        )
    };
    {
        // Make a new cookie. This is currently one of the less type-safe corners of Gotham.
        let cookie = "adjective=repeat; HttpOnly".to_owned();
        set_cookie(cookie, &mut response);
    }
    (state, response)
}
fn handler ( state : State ) -> ( State , Response ) { // Define a narrow scope so that state can be borrowed/moved later in the function. let adjective_from_cookie = { // Get the request headers. let headers : & Headers = Headers :: borrow_from ( & state ) ; // Get the Cookie header from the request. let maybe_cookie = headers . get :: < Cookie > ( ) ; // Get the value of the "adjective" cookie, if set. maybe_cookie . and_then ( | cookie | cookie . get ( " " ) . map ( | s | s . to_owned ( ) ) ) } ; let adjective = adjective_from_cookie . unwrap_or ( " " . to_owned ( ) ) ; let mut response = { create_response ( & state , StatusCode :: Ok , Some ( ( format ! ( " \n " adjective ) . as_bytes ( ) . to_vec ( ) , mime :: TEXT_PLAIN , ) ) , ) } ; { // Make a new cookie. This is currently one of the less type-safe corners of Gotham. let cookie = " " . to_owned ( ) ; set_cookie ( cookie , & mut response ) ; } ( state , response ) }
The first request will set a cookie, and subsequent requests will echo it back.
The first request will set a cookie and subsequent requests will echo it back .
state
State
state
State