Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: simplify featureset #24

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ mockito = "0.31.1"
tokio-test = "0.4.2"

[features]
default = ["sync", "local-cache"]
client = ["dep:thiserror", "dep:url"]
sync = ["client", "dep:ureq"]
local-cache = ["sync", "dep:cacache-sync"]
async = ["client", "dep:reqwest", "dep:reqwest-middleware", "dep:http-cache-reqwest"]
default = ["sync"]
sync = ["dep:thiserror", "dep:url", "dep:ureq", "dep:cacache-sync"]
async = ["dep:thiserror", "dep:url", "dep:reqwest", "dep:reqwest-middleware", "dep:http-cache-reqwest"]
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Rust library for accessing the latest LoL patch's ddragon data.
use ddragon::{cache_middleware::CacheMiddleware, DDragonClientError, DDragonClient};

fn main() -> Result<(), DDragonClientError> {
// Using caching, the preferred option.
// If you do not want caching enabled, disable the "local-cache" feature.
let client = DDragonClient::new("/path/to/your/cache/dir")?;

// If you want to use an existing agent
Expand All @@ -41,13 +39,9 @@ fn main() -> Result<(), DDragonClientError> {
The following crate features are available:

- `sync` (on by default) enables the synchronous client.
- Provides the `ddragon::client` module.
- Provides the `ddragon::client` and `ddragon::cache_middleware` module.
- Provides the re-exported `ddragon::DDragonClient` client.
- Adds `url`, `thiserror`, and `ureq` with the `json` feature enabled as dependencies.
- `local-cache` (on by default) enables the synchronous client.
- Provides the `ddragon::cache_middleware` module.
- Changes the default `DDragonClient::new()` implementation to set up caching.
- Adds `cacache-sync` as a dependency.
- Adds `cacache-sync`, `url`, `thiserror`, and `ureq` with the `json` feature enabled as dependencies.
- `async` enables the asynchronous client.
- Provides the `ddragon::async_client` module.
- Provides the re-exported `ddragon::AsyncDDragonClient` client.
Expand Down
10 changes: 1 addition & 9 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use url::Url;
#[cfg(test)]
use mockito;

#[cfg(feature = "local-cache")]
use crate::cache_middleware::CacheMiddleware;

use crate::{
Expand Down Expand Up @@ -57,7 +56,6 @@ impl DDragonClient {
Self::create(agent, Url::parse(&base_url)?)
}

#[cfg(feature = "local-cache")]
/// Creates a new client with the specified directory as the caching location
/// for any data the client downloads.
pub fn new(cache_dir: &str) -> Result<Self, DDragonClientError> {
Expand All @@ -67,18 +65,12 @@ impl DDragonClient {
Self::with_agent(agent)
}

#[cfg(any(test, not(feature = "local-cache")))]
#[cfg(test)]
fn new_no_cache() -> Result<Self, DDragonClientError> {
let agent = ureq::Agent::new();
Self::with_agent(agent)
}

#[cfg(not(feature = "local-cache"))]
/// Creates a new client without using a local cache.
pub fn new() -> Result<Self, DDragonClientError> {
Self::new_no_cache()
}

fn get_data_url(&self) -> Result<Url, url::ParseError> {
self.base_url
.join(&format!("/cdn/{}/data/en_US/", &self.version))
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod error;
#[cfg(any(feature = "sync", feature = "async"))]
pub use error::DDragonClientError;

#[cfg(feature = "local-cache")]
#[cfg(feature = "sync")]
/// Contains the local file caching middleware used for `ureq`.
pub mod cache_middleware;

Expand Down