Skip to content

Commit

Permalink
Don't expose BoxFuture in public API
Browse files Browse the repository at this point in the history
`ObjectStore::get` calls itself recursively, so the returned future
needs to be boxed. However, this is an implementation detail, there's no
reason to expose it in the public API. Instead, we can move the
recursive call to a separate `get_impl` function that handles the
boxing, and `get` can just be a standard async function.
  • Loading branch information
oscarwcl committed Nov 30, 2023
1 parent ae78ff9 commit fa4324a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions async-nats/src/jetstream/object_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,19 @@ impl ObjectStore {
/// # Ok(())
/// # }
/// ```
pub fn get<'bucket, 'future, T>(
pub async fn get<T: AsRef<str> + Send>(&self, object_name: T) -> Result<Object, GetError> {
self.get_impl(object_name).await
}

fn get_impl<'bucket, 'future, T>(
&'bucket self,
object_name: T,
) -> BoxFuture<'future, Result<Object, GetError>>
where
T: AsRef<str> + Send + 'future,
'bucket: 'future,
{
// Future needs to be boxed because get_impl calls itself recursively
Box::pin(async move {
let object_info = self.info(object_name).await?;
if let Some(ref options) = object_info.options {
Expand All @@ -125,7 +130,7 @@ impl ObjectStore {
let link_name = link_name.clone();
debug!("getting object via link");
if link.bucket == self.name {
return self.get(link_name).await;
return self.get_impl(link_name).await;
} else {
let bucket = self
.stream
Expand All @@ -135,7 +140,7 @@ impl ObjectStore {
.map_err(|err| {
GetError::with_source(GetErrorKind::Other, err)
})?;
let object = bucket.get(&link_name).await?;
let object = bucket.get_impl(&link_name).await?;
return Ok(object);
}
} else {
Expand Down

0 comments on commit fa4324a

Please sign in to comment.