diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0093938..3d8481e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -6,7 +6,8 @@ env: # This is required to enable the web_sys clipboard API which egui_web uses # https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html # https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html - RUSTFLAGS: --cfg=web_sys_unstable_apis + RUSTFLAGS: --cfg=web_sys_unstable_apis --deny warnings + RUSTDOCFLAGS: --deny warnings jobs: check_native: @@ -85,7 +86,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: clippy - args: --all-targets --all-features -- -D warnings -W clippy::all + args: --all-targets --all-features -- --deny warnings -W clippy::all doc: name: cargo doc diff --git a/check.sh b/check.sh new file mode 100755 index 0000000..b58bd63 --- /dev/null +++ b/check.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# This scripts runs various CI-like checks in a convenient way. + +set -eu +script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) +cd "$script_path" +set -x + +export RUSTFLAGS="--deny warnings" + +# https://github.com/ericseppanen/cargo-cranky/issues/8 +export RUSTDOCFLAGS="--deny warnings --deny rustdoc::missing_crate_level_docs" + +typos # cargo install typos-cli + +cargo fmt --all -- --check +cargo cranky --quiet --all-targets --all-features -- --deny warnings +cargo test --quiet --all-targets --all-features +cargo test --quiet --doc --all-features # checks all doc-tests + +cargo cranky --quiet --lib --target wasm32-unknown-unknown --all-features + +cargo doc --quiet --no-deps --all-features +cargo doc --quiet --document-private-items --no-deps --all-features + +cargo deny --all-features --log-level error check + +echo "All checks passed!" diff --git a/ehttp/src/multipart.rs b/ehttp/src/multipart.rs index 831d3c7..c8b4f6d 100644 --- a/ehttp/src/multipart.rs +++ b/ehttp/src/multipart.rs @@ -27,16 +27,10 @@ use mime::Mime; use rand::Rng; -use std::fs::File; use std::io::{self, Read, Write}; -use std::path::Path; const BOUNDARY_LEN: usize = 29; -fn opt_filename(path: &Path) -> Option<&str> { - path.file_name().and_then(|filename| filename.to_str()) -} - fn random_alphanumeric(len: usize) -> String { rand::thread_rng() .sample_iter(&rand::distributions::Uniform::from(0..=9)) @@ -45,12 +39,6 @@ fn random_alphanumeric(len: usize) -> String { .collect() } -fn mime_filename(path: &Path) -> (Mime, Option<&str>) { - let content_type = mime_guess::from_path(path); - let filename = opt_filename(path); - (content_type.first_or_octet_stream(), filename) -} - #[derive(Debug)] /// The Builder for the multipart pub struct MultipartBuilder { @@ -91,10 +79,16 @@ impl MultipartBuilder { /// * name file field name /// * path the sending file path #[cfg(not(target_arch = "wasm32"))] - pub fn add_file>(self, name: &str, path: P) -> io::Result { + pub fn add_file>(self, name: &str, path: P) -> io::Result { + fn mime_filename(path: &std::path::Path) -> (Mime, Option<&str>) { + let content_type = mime_guess::from_path(path); + let filename = path.file_name().and_then(|filename| filename.to_str()); + (content_type.first_or_octet_stream(), filename) + } + let path = path.as_ref(); let (content_type, filename) = mime_filename(path); - let mut file = File::open(path)?; + let mut file = std::fs::File::open(path)?; self.add_stream(&mut file, name, filename, Some(content_type)) } diff --git a/ehttp/src/types.rs b/ehttp/src/types.rs index 419f31f..86b4557 100644 --- a/ehttp/src/types.rs +++ b/ehttp/src/types.rs @@ -94,8 +94,8 @@ impl<'h> IntoIterator for &'h Headers { // ---------------------------------------------------------------------------- /// Determine if cross-origin requests lead to valid responses. +/// /// Based on -#[cfg(target_arch = "wasm32")] #[derive(Default, Clone, Copy, Debug)] pub enum Mode { /// If a request is made to another origin with this mode set, the result is an error. @@ -141,8 +141,9 @@ pub struct Request { /// ("Accept", "*/*"), … pub headers: Headers, - /// Request mode used on fetch. Only available on wasm builds - #[cfg(target_arch = "wasm32")] + /// Request mode used on fetch. + /// + /// Used on Web to control CORS. pub mode: Mode, } @@ -155,7 +156,6 @@ impl Request { url: url.to_string(), body: vec![], headers: Headers::new(&[("Accept", "*/*")]), - #[cfg(target_arch = "wasm32")] mode: Mode::default(), } } @@ -168,7 +168,6 @@ impl Request { url: url.to_string(), body: vec![], headers: Headers::new(&[("Accept", "*/*")]), - #[cfg(target_arch = "wasm32")] mode: Mode::default(), } } @@ -184,7 +183,6 @@ impl Request { ("Accept", "*/*"), ("Content-Type", "text/plain; charset=utf-8"), ]), - #[cfg(target_arch = "wasm32")] mode: Mode::default(), } } @@ -219,7 +217,6 @@ impl Request { url: url.to_string(), body: data, headers: Headers::new(&[("Accept", "*/*"), ("Content-Type", content_type.as_str())]), - #[cfg(target_arch = "wasm32")] mode: Mode::default(), } } @@ -236,7 +233,6 @@ impl Request { url: url.to_string(), body: serde_json::to_string(body)?.into_bytes(), headers: Headers::new(&[("Accept", "*/*"), ("Content-Type", "application/json")]), - #[cfg(target_arch = "wasm32")] mode: Mode::default(), }) } diff --git a/example_eframe/src/lib.rs b/example_eframe/src/lib.rs index 4dea7bd..0d06752 100644 --- a/example_eframe/src/lib.rs +++ b/example_eframe/src/lib.rs @@ -1,3 +1,5 @@ +//! Example application using [`eframe`]. + mod app; pub use app::DemoApp; diff --git a/example_eframe/src/web.rs b/example_eframe/src/web.rs index d8bfcd4..3dc7a41 100644 --- a/example_eframe/src/web.rs +++ b/example_eframe/src/web.rs @@ -30,7 +30,7 @@ impl WebHandle { .start( canvas_id, eframe::WebOptions::default(), - Box::new(|_cc| Box::new(DemoApp::default())), + Box::new(|_cc| Box::::default()), ) .await }