Skip to content

Commit 18e6d75

Browse files
committed
Remove Result from Request::cookie
1 parent 589abaf commit 18e6d75

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/middleware/cookies.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ use std::sync::{Arc, RwLock};
1313
///
1414
/// # Examples
1515
///
16-
/// ```rust
17-
///
16+
/// ```
1817
/// let mut app = tide::Server::new();
19-
/// app.at("/get").get(|cx: tide::Request<()>| async move { cx.cookie("testCookie").unwrap().unwrap().value().to_string() });
18+
/// app.at("/get").get(|cx: tide::Request<()>| async move { cx.cookie("testCookie").unwrap().value().to_string() });
2019
/// app.at("/set").get(|_| async {
2120
/// let mut res = tide::Response::new(200);
2221
/// res.set_cookie(cookie::Cookie::new("testCookie", "NewCookieValue"));
2322
/// res
2423
/// });
25-
///
2624
/// ```
2725
#[derive(Debug, Clone, Default)]
2826
pub(crate) struct CookiesMiddleware;

src/request.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use async_std::task::{Context, Poll};
1010
use std::pin::Pin;
1111
use std::{str::FromStr, sync::Arc};
1212

13-
use crate::error::Error;
1413
use crate::middleware::cookies::CookieData;
1514

1615
pin_project_lite::pin_project! {
@@ -299,13 +298,13 @@ impl<State> Request<State> {
299298
}
300299

301300
/// returns a `Cookie` by name of the cookie.
302-
pub fn cookie(&self, name: &str) -> Result<Option<Cookie<'static>>, Error> {
301+
pub fn cookie(&self, name: &str) -> Option<Cookie<'static>> {
303302
let cookie_data = self
304303
.local::<CookieData>()
305304
.expect("should always be set by the cookies middleware");
306305

307306
let locked_jar = cookie_data.content.read().unwrap();
308-
Ok(locked_jar.get(name).cloned())
307+
locked_jar.get(name).cloned()
309308
}
310309
}
311310

tests/cookies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tide::{Request, Response, Server};
99
static COOKIE_NAME: &str = "testCookie";
1010

1111
async fn retrieve_cookie(cx: Request<()>) -> String {
12-
cx.cookie(COOKIE_NAME).unwrap().unwrap().value().to_string()
12+
cx.cookie(COOKIE_NAME).unwrap().value().to_string()
1313
}
1414

1515
async fn set_cookie(_req: Request<()>) -> Response {

0 commit comments

Comments
 (0)