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

unresolved import treemux::static_files #61

Closed
davehorner opened this issue Jan 6, 2022 · 4 comments
Closed

unresolved import treemux::static_files #61

davehorner opened this issue Jan 6, 2022 · 4 comments

Comments

@davehorner
Copy link

davehorner commented Jan 6, 2022

When I use the example:
cargo run --example staticfile --features="hyper-staticfile"
The example compiles and runs fine from within the treemux project.

error[E0432]: unresolved import `treemux::static_files`
 --> src\main.rs:8:15
  |
8 | use treemux::{static_files };
  |               ^^^^^^^^^^^^ no `static_files` in the root

When I hover the red line'd static_files in vscode I get:

pub fn static_files(root: impl Into<PathBuf>) -> impl Into<RequestHandler>
Create a handler for serving static files

```rust let mut router = Treemux::builder(); router.get("/", static_files("./examples/static")); router.get("/*", static_files("./examples/static"));

let _server = Server::bind(&([127, 0, 0, 1], 3000).into()).serve(router.into_service()).await?;

unresolved import `treemux::static_files`

no `static_files` in the rootrustc(E0432)
main.rs(8, 15): no `static_files` in the root

I see that static_files is defined in mux.rs:264 which is annotated #[cfg(feature = "hyper-staticfile")]. I've pulled all the cargo feature stuff into my Cargo.toml and still can't understand why I can't get static_files in treemap.

I've tried doing a cargo clean and that did not resolve the no static_files in the root error.
any suggestions?

@casualjim
Copy link
Owner

have you tried adding the hyper-staticfile crate? it should enable the feature automatically if you add that crate

@davehorner
Copy link
Author

[package]
name = "rust_mpv"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "rust_mpv"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dev-dependencies]
env_logger = "0.9"
serde = "1"
serde_json = "1"
hyper-staticfile = "0.8"
tracing = { version="0.1" }
tracing-subscriber =  {version = "0.3.2", features = ["env-filter", "fmt"]}
test-env-log = "0.2"

[dependencies]
subprocess = "0.2.8"
hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1", features = ["full"] }
url = "2.2.2"
rand = "0.8.4"
treemux = "0.7.2"
hyper-staticfile = { version = "0.8", optional=true  }
async-compression = { version = "0.3", optional = true }
tracing = { version = "0.1.29", optional = true }

[features]
default = []
full = ["hyper-staticfile", "async-compression", "tracing"]

Yes, its been there.

@casualjim
Copy link
Owner

casualjim commented Jan 6, 2022

It starts to work when I declare the treemux dependency like this:

treemux = { version = "0.7.2", features = ["hyper-staticfile"] }

but given you included all the optional dependencies, you can just add the full features

treemux = { version = "0.7.2", features = ["full"] }

@davehorner
Copy link
Author

thank you for helping me! it is working with your declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants