Skip to content

Commit fbbf538

Browse files
committed
Fix unneeded pass-by-value
1 parent 3124ddf commit fbbf538

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/token.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,18 @@ pub fn new(req: &mut Request) -> CargoResult<Response> {
153153
})?;
154154

155155
if length > max_post_size {
156-
return Err(bad_request(format!("max post size is: {}", max_post_size)));
156+
return Err(bad_request(&format!("max post size is: {}", max_post_size)));
157157
}
158158

159159
let mut json = vec![0; length as usize];
160160
read_fill(req.body(), &mut json)?;
161161

162162
let json = String::from_utf8(json).map_err(|_| {
163-
bad_request("json body was not valid utf-8")
163+
bad_request(&"json body was not valid utf-8")
164164
})?;
165165

166166
let new: NewApiTokenRequest = json::decode(&json).map_err(|e| {
167-
bad_request(format!("invalid new token request: {:?}", e))
167+
bad_request(&format!("invalid new token request: {:?}", e))
168168
})?;
169169

170170
let name = &new.api_token.name;
@@ -177,7 +177,7 @@ pub fn new(req: &mut Request) -> CargoResult<Response> {
177177
let max_token_per_user = 500;
178178
let count = ApiToken::count_for_user(&*req.db_conn()?, user.id)?;
179179
if count >= max_token_per_user {
180-
return Err(bad_request(format!(
180+
return Err(bad_request(&format!(
181181
"maximum tokens per user is: {}",
182182
max_token_per_user
183183
)));
@@ -196,7 +196,7 @@ pub fn new(req: &mut Request) -> CargoResult<Response> {
196196
pub fn revoke(req: &mut Request) -> CargoResult<Response> {
197197
let user = req.user()?;
198198
let id = req.params()["id"].parse().map_err(|e| {
199-
bad_request(format!("invalid token id: {:?}", e))
199+
bad_request(&format!("invalid token id: {:?}", e))
200200
})?;
201201

202202
ApiToken::delete(&*req.db_conn()?, user.id, id)?;

src/util/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ pub fn human<S: ToString + ?Sized>(error: &S) -> Box<CargoError> {
327327
///
328328
/// Since this is going back to the UI these errors are treated the same as
329329
/// `human` errors, other than the HTTP status code.
330-
pub fn bad_request<S: ToString>(error: S) -> Box<CargoError> {
330+
pub fn bad_request<S: ToString + ?Sized>(error: &S) -> Box<CargoError> {
331331
Box::new(BadRequest(error.to_string()))
332332
}
333333

0 commit comments

Comments
 (0)