Skip to content

Commit

Permalink
Fix features + Clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsil committed Apr 2, 2024
1 parent 095186f commit 1e67e8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/download.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#[cfg(not(feature = "tokio"))]
#[cfg(not(feature = "ureq"))]
#[cfg(not(feature="tokio"))]
fn main() {
}

#[cfg(feature = "ureq")]
#[cfg(not(feature="tokio"))]
fn main() {
let api = hf_hub::api::sync::Api::new().unwrap();

Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#![deny(missing_docs)]
#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]
#[cfg(any(feature="tokio", feature="ureq"))]
use rand::{distributions::Alphanumeric, Rng};
use std::io::Write;
use std::path::PathBuf;

/// The actual Api to interact with the hub.
#[cfg(any(feature="tokio", feature="ureq"))]
pub mod api;

/// The type of repo to interact with
Expand Down Expand Up @@ -104,6 +106,7 @@ impl Cache {
self.repo(Repo::new(model_id, RepoType::Space))
}

#[cfg(any(feature="tokio", feature="ureq"))]
pub(crate) fn temp_path(&self) -> PathBuf {
let mut path = self.path().clone();
path.push("tmp");
Expand Down Expand Up @@ -172,6 +175,8 @@ impl CacheRepo {
Ok(())
}


#[cfg(any(feature="tokio", feature="ureq"))]
pub(crate) fn blob_path(&self, etag: &str) -> PathBuf {
let mut blob_path = self.path();
blob_path.push("blobs");
Expand Down Expand Up @@ -257,6 +262,7 @@ impl Repo {
}

/// The actual URL part of the repo
#[cfg(any(feature="tokio", feature="ureq"))]
pub fn url(&self) -> String {
match self.repo_type {
RepoType::Model => self.repo_id.to_string(),
Expand All @@ -270,11 +276,13 @@ impl Repo {
}

/// Revision needs to be url escaped before being used in a URL
#[cfg(any(feature="tokio", feature="ureq"))]
pub fn url_revision(&self) -> String {
self.revision.replace('/', "%2F")
}

/// Used to compute the repo's url part when accessing the metadata of the repo
#[cfg(any(feature="tokio", feature="ureq"))]
pub fn api_url(&self) -> String {
let prefix = match self.repo_type {
RepoType::Model => "models",
Expand Down

0 comments on commit 1e67e8d

Please sign in to comment.