Skip to content

Commit

Permalink
[fs] breaking: remove async_std crate and remove double allocation …
Browse files Browse the repository at this point in the history
…in `resolver` field

Since both  and  allocate memory on the heap, we don't need both ;  works as well.
  • Loading branch information
auguwu committed Aug 4, 2024
1 parent b23f8fb commit 7d54086
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
2 changes: 0 additions & 2 deletions crates/fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ rust-version.workspace = true
file-format = ["dep:infer", "dep:file-format"]
serde_json = ["dep:serde_json"]
serde_yaml = ["dep:serde_yaml"]
async-std = ["dep:async-std"]
default = ["file-format", "serde_json"]
tracing = ["dep:tracing"]
serde = ["dep:serde"]
log = ["dep:log"]

[dependencies]
async-std = { version = "1.12.0", optional = true }
async-trait = "0.1.80"
bytes = "1.6.0"
dirs = "5.0.1"
Expand Down
11 changes: 3 additions & 8 deletions crates/fs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ use std::{
sync::Arc,
time::SystemTime,
};

#[cfg(not(feature = "async_std"))]
use tokio::{fs, io::*};

#[cfg(feature = "async_std")]
use async_std::{fs, io::*};

#[cfg(feature = "tracing")]
use tracing::instrument;

/// Represents an implementation of a [`StorageService`](remi::StorageService) for the
/// local filesystem.
#[derive(Clone)]
pub struct StorageService {
resolver: Arc<Box<dyn ContentTypeResolver>>,
resolver: Arc<dyn ContentTypeResolver>,
config: Config,
}

Expand All @@ -57,14 +52,14 @@ impl StorageService {
/// Creates a new [`StorageService`] instance with a provided configuration object.
pub fn with_config(config: Config) -> StorageService {
StorageService {
resolver: Arc::new(Box::new(default_resolver)),
resolver: Arc::new(default_resolver),
config,
}
}

/// Updates the given [`ContentTypeResolver`] to something else.
pub fn with_resolver<R: ContentTypeResolver + 'static>(mut self, resolver: R) -> StorageService {
self.resolver = Arc::new(Box::new(resolver));
self.resolver = Arc::new(resolver);
self
}

Expand Down

1 comment on commit 7d54086

@auguwu
Copy link
Member Author

@auguwu auguwu commented on 7d54086 Aug 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate Git sometimes, so here is what I wanted to say:

Since both Arc and Box allocate memory on the heap, we don't need both Arc<Box<dyn ...>>; Arc<dyn ...> works as well.

Please sign in to comment.