Skip to content

Commit c5cf16f

Browse files
authored
refactor: Let BlobObject::from_name() take &str (#6571)
This way, all the callers don't have to call to_string()
1 parent 3df693a commit c5cf16f

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/blob.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a> BlobObject<'a> {
155155
return Err(format_err!("bad blob name: {}", rel_path.display()));
156156
}
157157
let name = rel_path.to_str().context("wrong name")?;
158-
BlobObject::from_name(context, name.to_string())
158+
BlobObject::from_name(context, name)
159159
}
160160

161161
/// Returns a [BlobObject] for an existing blob.
@@ -164,13 +164,13 @@ impl<'a> BlobObject<'a> {
164164
/// prefixed, as returned by [BlobObject::as_name]. This is how
165165
/// you want to create a [BlobObject] for a filename read from the
166166
/// database.
167-
pub fn from_name(context: &'a Context, name: String) -> Result<BlobObject<'a>> {
168-
let name: String = match name.starts_with("$BLOBDIR/") {
169-
true => name.splitn(2, '/').last().unwrap().to_string(),
167+
pub fn from_name(context: &'a Context, name: &str) -> Result<BlobObject<'a>> {
168+
let name = match name.starts_with("$BLOBDIR/") {
169+
true => name.splitn(2, '/').last().unwrap(),
170170
false => name,
171171
};
172-
if !BlobObject::is_acceptible_blob_name(&name) {
173-
return Err(format_err!("not an acceptable blob name: {}", &name));
172+
if !BlobObject::is_acceptible_blob_name(name) {
173+
return Err(format_err!("not an acceptable blob name: {}", name));
174174
}
175175
Ok(BlobObject {
176176
blobdir: context.get_blobdir(),

src/mimefactory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ async fn build_body_file(context: &Context, msg: &Message) -> Result<MimePart<'s
16991699

17001700
async fn build_avatar_file(context: &Context, path: &str) -> Result<String> {
17011701
let blob = match path.starts_with("$BLOBDIR/") {
1702-
true => BlobObject::from_name(context, path.to_string())?,
1702+
true => BlobObject::from_name(context, path)?,
17031703
false => BlobObject::from_path(context, path.as_ref())?,
17041704
};
17051705
let body = fs::read(blob.to_abs_path()).await?;

src/net/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async fn http_cache_get(context: &Context, url: &str) -> Result<Option<(Response
167167
};
168168
let is_stale = now > stale_timestamp;
169169

170-
let blob_object = BlobObject::from_name(context, blob_name)?;
170+
let blob_object = BlobObject::from_name(context, &blob_name)?;
171171
let blob_abs_path = blob_object.to_abs_path();
172172
let blob = match fs::read(blob_abs_path)
173173
.await

src/param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl Params {
367367
return Ok(None);
368368
};
369369
ensure!(val.starts_with("$BLOBDIR/"));
370-
let blob = BlobObject::from_name(context, val.to_string())?;
370+
let blob = BlobObject::from_name(context, val)?;
371371
Ok(Some(blob))
372372
}
373373

0 commit comments

Comments
 (0)