From 88ea1c2f78b72582c993ebceda8f7b2c0d33b786 Mon Sep 17 00:00:00 2001 From: reshane Date: Sun, 19 Jan 2025 13:08:46 -0500 Subject: [PATCH 1/2] Add tests github actions --- .github/workflows/test.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9403b16 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: Run Tests + +on: + push: + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Restore Cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo.bin + ~/.cargo/git + ~/.cargo/registry + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: run tests + run: cargo test From 0ce0f084467946adaa0afea64ee35d964451392a Mon Sep 17 00:00:00 2001 From: reshane Date: Sun, 19 Jan 2025 13:22:52 -0500 Subject: [PATCH 2/2] Fix Docs --- src/decoder.rs | 10 +++++++--- src/encoder.rs | 18 +++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/decoder.rs b/src/decoder.rs index cd43422..81e4a30 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -30,10 +30,14 @@ impl Decoder { /// - `WbmpError::IoError` occurs if the image headers are malformed or /// if another IoError occurs while reading from the provided `reader` /// - /// # Examples + /// ## Examples /// ``` - /// let f = BufReader::new(File::open("path/to/file.wbmp").unwrap()); - /// let mut decoder = Decoder::new(f)?; + /// use wbmp::Decoder; + /// use std::{fs::File, io::BufReader}; + /// let f = BufReader::new( + /// File::open("./tests/images/sample_640x426.wbmp").unwrap() + /// ); + /// let mut decoder = Decoder::new(f).unwrap(); /// ``` pub fn new(reader: R) -> WbmpResult> { let mut decoder = Self::new_decoder(reader); diff --git a/src/encoder.rs b/src/encoder.rs index ecc8cff..8dd2540 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -19,18 +19,22 @@ impl<'a, W: Write> Encoder<'a, W> { /// Create a new decoder that decodes from the stream ```reader```. /// - /// # Examples + /// ## Examples /// ``` + /// use std::fs::File; + /// use wbmp::Encoder; /// let img_data = vec![ - /// 0xFF, 0x00, 0xFF, 0x00, - /// 0xFF, 0x00, 0xFF, 0x00, - /// 0xFF, 0x00, 0xFF, 0x00, - /// 0xFF, 0x00, 0xFF, 0x00, + /// 0xFF, 0x00, 0xFF, 0x00, + /// 0xFF, 0x00, 0xFF, 0x00, + /// 0xFF, 0x00, 0xFF, 0x00, + /// 0xFF, 0x00, 0xFF, 0x00, /// ]; /// let (width, height) = (4, 4); - /// let mut out_file = File::create("checker.wbmp")?; + /// let mut out_file = vec![]; /// let mut encoder = Encoder::new(&mut out_file); - /// encoder.encode(&img_data, width, height, wbmp::ColorType::Luma8)?; + /// encoder.encode( + /// &img_data, width, height, wbmp::ColorType::Luma8 + /// ).unwrap() /// ``` pub fn new(writer: &'a mut W) -> Self { Encoder {