Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ impl<R: BufRead + Seek> Decoder<R> {
/// - `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<Decoder<R>> {
let mut decoder = Self::new_decoder(reader);
Expand Down
18 changes: 11 additions & 7 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading