Skip to content

Commit 0aaf2b5

Browse files
committed
fix: check errors
1 parent d8af067 commit 0aaf2b5

File tree

8 files changed

+17
-22
lines changed

8 files changed

+17
-22
lines changed

packages/located-error/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ where
4848
location: Box<Location<'a>>,
4949
}
5050

51-
impl<'a, E> std::fmt::Display for LocatedError<'a, E>
51+
impl<E> std::fmt::Display for LocatedError<'_, E>
5252
where
5353
E: Error + ?Sized + Send + Sync,
5454
{
@@ -57,7 +57,7 @@ where
5757
}
5858
}
5959

60-
impl<'a, E> Error for LocatedError<'a, E>
60+
impl<E> Error for LocatedError<'_, E>
6161
where
6262
E: Error + ?Sized + Send + Sync + 'static,
6363
{
@@ -66,7 +66,7 @@ where
6666
}
6767
}
6868

69-
impl<'a, E> Clone for LocatedError<'a, E>
69+
impl<E> Clone for LocatedError<'_, E>
7070
where
7171
E: Error + ?Sized + Send + Sync,
7272
{

src/mailer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ fn build_letter(verification_url: &str, username: &str, builder: MessageBuilder)
179179

180180
fn build_content(verification_url: &str, username: &str) -> Result<(String, String), tera::Error> {
181181
let plain_body = format!(
182-
r#"
182+
"
183183
Welcome to Torrust, {username}!
184184
185185
Please click the confirmation link below to verify your account.
186186
{verification_url}
187187
188188
If this account wasn't made by you, you can ignore this email.
189-
"#
189+
"
190190
);
191191
let mut context = Context::new();
192192
context.insert("verification", &verification_url);

src/models/info_hash.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'de> serde::de::Deserialize<'de> for InfoHash {
336336

337337
struct InfoHashVisitor;
338338

339-
impl<'v> serde::de::Visitor<'v> for InfoHashVisitor {
339+
impl serde::de::Visitor<'_> for InfoHashVisitor {
340340
type Value = InfoHash;
341341

342342
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

src/web/api/server/v1/auth.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl Authentication {
117117
/// # Errors
118118
///
119119
/// This function will return an error if it can get claims from the request
120-
pub async fn get_user_id_from_bearer_token(&self, maybe_token: &Option<BearerToken>) -> Result<UserId, ServiceError> {
120+
pub async fn get_user_id_from_bearer_token(&self, maybe_token: Option<BearerToken>) -> Result<UserId, ServiceError> {
121121
let claims = self.get_claims_from_bearer_token(maybe_token).await?;
122122
Ok(claims.user.user_id)
123123
}
@@ -130,7 +130,7 @@ impl Authentication {
130130
///
131131
/// - Return an `ServiceError::TokenNotFound` if `HeaderValue` is `None`.
132132
/// - Pass through the `ServiceError::TokenInvalid` if unable to verify the JWT.
133-
async fn get_claims_from_bearer_token(&self, maybe_token: &Option<BearerToken>) -> Result<UserClaims, ServiceError> {
133+
async fn get_claims_from_bearer_token(&self, maybe_token: Option<BearerToken>) -> Result<UserClaims, ServiceError> {
134134
match maybe_token {
135135
Some(token) => match self.verify_jwt(&token.value()).await {
136136
Ok(claims) => Ok(claims),
@@ -166,7 +166,7 @@ pub async fn get_optional_logged_in_user(
166166
app_data: Arc<AppData>,
167167
) -> Result<Option<UserId>, ServiceError> {
168168
match maybe_bearer_token {
169-
Some(bearer_token) => match app_data.auth.get_user_id_from_bearer_token(&Some(bearer_token)).await {
169+
Some(bearer_token) => match app_data.auth.get_user_id_from_bearer_token(Some(bearer_token)).await {
170170
Ok(user_id) => Ok(Some(user_id)),
171171
Err(error) => Err(error),
172172
},

src/web/api/server/v1/extractors/optional_user_id.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ where
2020
type Rejection = Response;
2121

2222
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
23-
/* let maybe_bearer_token = match bearer_token::Extract::from_request_parts(parts, state).await {
24-
Ok(maybe_bearer_token) => maybe_bearer_token.0,
25-
Err(_) => return Err(ServiceError::TokenNotFound.into_response()),
26-
}; */
27-
2823
let bearer_token = match bearer_token::Extract::from_request_parts(parts, state).await {
2924
Ok(bearer_token) => bearer_token.0,
3025
Err(_) => None,
@@ -33,7 +28,7 @@ where
3328
//Extracts the app state
3429
let app_data = Arc::from_ref(state);
3530

36-
match app_data.auth.get_user_id_from_bearer_token(&bearer_token).await {
31+
match app_data.auth.get_user_id_from_bearer_token(bearer_token).await {
3732
Ok(user_id) => Ok(ExtractOptionalLoggedInUser(Some(user_id))),
3833
Err(_) => Ok(ExtractOptionalLoggedInUser(None)),
3934
}

src/web/api/server/v1/extractors/user_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where
2929
//Extracts the app state
3030
let app_data = Arc::from_ref(state);
3131

32-
match app_data.auth.get_user_id_from_bearer_token(&maybe_bearer_token).await {
32+
match app_data.auth.get_user_id_from_bearer_token(maybe_bearer_token).await {
3333
Ok(user_id) => Ok(ExtractLoggedInUser(user_id)),
3434
Err(_) => Err(ServiceError::LoggedInUserNotFound.into_response()),
3535
}

tests/e2e/web/api/v1/contexts/torrent/asserts.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::e2e::environment::TestEnv;
1414
pub async fn canonical_torrent_for(
1515
mut uploaded_torrent: Torrent,
1616
env: &TestEnv,
17-
downloader: &Option<LoggedInUserData>,
17+
downloader: Option<&LoggedInUserData>,
1818
) -> Torrent {
1919
let tracker_url = env.server_settings().unwrap().tracker.url.to_string();
2020

@@ -23,8 +23,8 @@ pub async fn canonical_torrent_for(
2323
None => None,
2424
};
2525

26-
uploaded_torrent.announce = Some(build_announce_url(&tracker_url, &tracker_key));
27-
uploaded_torrent.announce_list = Some(build_announce_list(&tracker_url, &tracker_key));
26+
uploaded_torrent.announce = Some(build_announce_url(&tracker_url, tracker_key.as_ref()));
27+
uploaded_torrent.announce_list = Some(build_announce_list(&tracker_url, tracker_key.as_ref()));
2828

2929
uploaded_torrent
3030
}
@@ -56,15 +56,15 @@ pub async fn get_user_tracker_key(logged_in_user: &LoggedInUserData, env: &TestE
5656
Some(tracker_key)
5757
}
5858

59-
pub fn build_announce_url(tracker_url: &str, tracker_key: &Option<TrackerKey>) -> String {
59+
pub fn build_announce_url(tracker_url: &str, tracker_key: Option<&TrackerKey>) -> String {
6060
if let Some(key) = &tracker_key {
6161
format!("{tracker_url}/{}", key.key)
6262
} else {
6363
tracker_url.to_string()
6464
}
6565
}
6666

67-
fn build_announce_list(tracker_url: &str, tracker_key: &Option<TrackerKey>) -> Vec<Vec<String>> {
67+
fn build_announce_list(tracker_url: &str, tracker_key: Option<&TrackerKey>) -> Vec<Vec<String>> {
6868
if let Some(key) = &tracker_key {
6969
vec![vec![format!("{tracker_url}/{}", key.key)], vec![format!("{tracker_url}")]]
7070
} else {

tests/e2e/web/api/v1/contexts/torrent/contract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ mod for_guests {
325325

326326
let downloaded_torrent = decode_torrent(&response.bytes).expect("could not decode downloaded torrent");
327327

328-
let expected_downloaded_torrent = canonical_torrent_for(uploaded_torrent, &env, &None).await;
328+
let expected_downloaded_torrent = canonical_torrent_for(uploaded_torrent, &env, None).await;
329329

330330
assert_eq!(downloaded_torrent, expected_downloaded_torrent);
331331
}

0 commit comments

Comments
 (0)