From e91bbc38c5f029da4c710cbaff0e23b699f6ab34 Mon Sep 17 00:00:00 2001 From: Zoey Date: Thu, 19 Aug 2021 13:59:00 -0700 Subject: [PATCH] Switch to stable toolchain --- .github/workflows/main.yml | 6 ---- rust-toolchain.toml | 2 ++ src/builder.rs | 4 +-- src/lib.rs | 3 -- src/serving.rs | 61 +++++++++++++++++--------------------- 5 files changed, 31 insertions(+), 45 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1b84d27..c468389 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,12 +27,6 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - - name: Install nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - # Runs a single command using the runners shell - name: Build site run: | diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..292fe49 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "stable" diff --git a/src/builder.rs b/src/builder.rs index 1d4c125..bcb8c44 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -57,9 +57,7 @@ impl<'a> SiteBuilder<'a> { /// Prepares the site builder for use. pub fn prepare(mut self) -> anyhow::Result { let build_static_path = self.build_path.join(STATIC_PATH); - if std::fs::try_exists(&self.build_path) - .context("Failed check if build directory exists")? - { + if self.build_path.exists() { if build_static_path.exists() { std::fs::remove_dir_all(&build_static_path) .context("Failed to remove old static directory")?; diff --git a/src/lib.rs b/src/lib.rs index 60bd90d..02fd1f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,3 @@ -#![feature(path_try_exists)] -#![feature(async_closure)] - mod builder; #[cfg(feature = "serve")] pub mod serving; diff --git a/src/serving.rs b/src/serving.rs index 3646572..7df525a 100644 --- a/src/serving.rs +++ b/src/serving.rs @@ -231,45 +231,40 @@ impl Site { .or(warp::any().and(warp::get()).and( warp::path::full() .and(with_build_path(build_path.clone())) - .and_then( - async move |path: FullPath, - build_path: PathBuf| - -> Result { - // Serve static files - let p = &path.as_str()[1..]; + .and_then(move |path: FullPath, build_path: PathBuf| async move { + // Serve static files + let p = &path.as_str()[1..]; - if p == "static/_dev.js" { - let res = - Response::new(include_str!("./refresh_websocket.js").into()); - return Ok(res); - } + if p == "static/_dev.js" { + let res = Response::new(include_str!("./refresh_websocket.js").into()); + return Ok(res); + } - let mut p = build_path.join(p); + let mut p = build_path.join(p); - if !p.exists() { - p = p.with_extension("html"); - } - if p.is_dir() { - p = p.join("index.html"); - } + if !p.exists() { + p = p.with_extension("html"); + } + if p.is_dir() { + p = p.join("index.html"); + } - if p.exists() { - let mut res = Response::new("".into()); - match std::fs::read_to_string(&p) { - Ok(body) => { - *res.body_mut() = body.into(); - } - Err(e) => { - eprintln!("{}", e); - *res.body_mut() = format!("Failed to load: {}", e).into(); - *res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - } + if p.exists() { + let mut res = Response::new("".into()); + match std::fs::read_to_string(&p) { + Ok(body) => { + *res.body_mut() = body.into(); + } + Err(e) => { + eprintln!("{}", e); + *res.body_mut() = format!("Failed to load: {}", e).into(); + *res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; } - return Ok(res); } - Err(warp::reject()) - }, - ), + return Ok(res); + } + Err(warp::reject()) + }), )) .or(warp::any() .and(warp::path::full())