mercurial_types: make envelope functions use generics instead of trait objects

Summary: Make these functions generic so that callers don't need to construct a trait object whenever they want to call them. Passing in a trait object should still work so existing callsites should not be affected.

Reviewed By: krallin

Differential Revision: D20225830

fbshipit-source-id: df0389b0f19aa44aaa89682198f43cb9f1d84b25
This commit is contained in:
Arun Kulshreshtha 2020-03-03 15:08:43 -08:00 committed by Facebook Github Bot
parent f8d0ad25a2
commit 78adda0589
2 changed files with 10 additions and 13 deletions

View File

@ -78,9 +78,9 @@ impl ManifestContent {
} }
} }
pub fn fetch_raw_manifest_bytes( pub fn fetch_raw_manifest_bytes<B: Blobstore>(
ctx: CoreContext, ctx: CoreContext,
blobstore: &Arc<dyn Blobstore>, blobstore: &B,
manifest_id: HgManifestId, manifest_id: HgManifestId,
) -> BoxFuture<HgBlob, Error> { ) -> BoxFuture<HgBlob, Error> {
fetch_manifest_envelope(ctx, blobstore, manifest_id) fetch_manifest_envelope(ctx, blobstore, manifest_id)
@ -92,9 +92,9 @@ pub fn fetch_raw_manifest_bytes(
.boxify() .boxify()
} }
pub fn fetch_manifest_envelope( pub fn fetch_manifest_envelope<B: Blobstore>(
ctx: CoreContext, ctx: CoreContext,
blobstore: &Arc<dyn Blobstore>, blobstore: &B,
manifest_id: HgManifestId, manifest_id: HgManifestId,
) -> impl Future<Item = HgManifestEnvelope, Error = Error> { ) -> impl Future<Item = HgManifestEnvelope, Error = Error> {
fetch_manifest_envelope_opt(ctx, blobstore, manifest_id) fetch_manifest_envelope_opt(ctx, blobstore, manifest_id)
@ -109,9 +109,9 @@ pub fn fetch_manifest_envelope(
} }
/// Like `fetch_manifest_envelope`, but returns None if the manifest wasn't found. /// Like `fetch_manifest_envelope`, but returns None if the manifest wasn't found.
pub fn fetch_manifest_envelope_opt( pub fn fetch_manifest_envelope_opt<B: Blobstore>(
ctx: CoreContext, ctx: CoreContext,
blobstore: &Arc<dyn Blobstore>, blobstore: &B,
node_id: HgManifestId, node_id: HgManifestId,
) -> impl Future<Item = Option<HgManifestEnvelope>, Error = Error> { ) -> impl Future<Item = Option<HgManifestEnvelope>, Error = Error> {
let blobstore_key = node_id.blobstore_key(); let blobstore_key = node_id.blobstore_key();

View File

@ -5,9 +5,6 @@
* GNU General Public License version 2. * GNU General Public License version 2.
*/ */
use std::sync::Arc;
use blobstore::Blobstore;
use bytes::Bytes; use bytes::Bytes;
use futures::compat::Future01CompatExt; use futures::compat::Future01CompatExt;
use mercurial_types::{ use mercurial_types::{
@ -35,8 +32,8 @@ impl HgTreeContext {
manifest_id: HgManifestId, manifest_id: HgManifestId,
) -> Result<Self, MononokeError> { ) -> Result<Self, MononokeError> {
let ctx = repo.ctx().clone(); let ctx = repo.ctx().clone();
let blobstore: Arc<dyn Blobstore> = Arc::new(repo.blob_repo().blobstore().clone()); let blobstore = repo.blob_repo().blobstore();
let envelope = fetch_manifest_envelope(ctx, &blobstore, manifest_id) let envelope = fetch_manifest_envelope(ctx, blobstore, manifest_id)
.compat() .compat()
.await?; .await?;
Ok(Self { repo, envelope }) Ok(Self { repo, envelope })
@ -47,8 +44,8 @@ impl HgTreeContext {
manifest_id: HgManifestId, manifest_id: HgManifestId,
) -> Result<Option<Self>, MononokeError> { ) -> Result<Option<Self>, MononokeError> {
let ctx = repo.ctx().clone(); let ctx = repo.ctx().clone();
let blobstore: Arc<dyn Blobstore> = Arc::new(repo.blob_repo().blobstore().clone()); let blobstore = repo.blob_repo().blobstore();
let envelope = fetch_manifest_envelope_opt(ctx, &blobstore, manifest_id) let envelope = fetch_manifest_envelope_opt(ctx, blobstore, manifest_id)
.compat() .compat()
.await?; .await?;
Ok(envelope.map(move |envelope| Self { repo, envelope })) Ok(envelope.map(move |envelope| Self { repo, envelope }))