Skip to content

Commit

Permalink
resize_buf: use slice, and not experimental split_arr
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Jan 28, 2024
1 parent 181da7d commit 2f1b730
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ serde-json-core = "0.4.0"
[dev-dependencies]
base64 = { version = "0.13.0", default-features = false }
bytemuck = "1.7.2"
embedded-hal-mock = "0.10.0"

[features]
default = [ ]
26 changes: 22 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Protocol for transmitting: <https://dev.blues.io/notecard/notecard-guides/serial-over-i2c-protocol/>
//! API: <https://dev.blues.io/reference/notecard-api/introduction/>
//!
#![feature(split_array)]
#![feature(type_changing_struct_update)]
#![cfg_attr(not(test), no_std)]

Expand Down Expand Up @@ -185,9 +184,8 @@ impl<IOM: Write<SevenBitAddress> + Read<SevenBitAddress>, const BUF_SIZE: usize>
if B < self.buf.len() {
Err(NoteError::BufOverflow)
} else {
let (buf, _) = self.buf.split_array_ref::<B>();
Ok(Notecard {
buf: Vec::<_, B>::from_slice(buf).unwrap(),
buf: Vec::<_, B>::from_slice(&self.buf).unwrap(),
..self
})
}
Expand Down Expand Up @@ -642,4 +640,24 @@ impl<
}

#[cfg(test)]
mod tests {}
mod tests {
use super::*;
use embedded_hal_mock::eh0::i2c::Mock;

pub fn new_mock() -> Notecard<Mock> {
// let exp = [ Transaction::write(0x17, vec![]) ];
let i2c = Mock::new(&[]);
Notecard::new(i2c)
}

#[test]
fn resize_buf() {
let c = new_mock();
assert_eq!(c.buf.capacity(), DEFAULT_BUF_SIZE);

let mut c = c.resize_buf::<1024>().unwrap();
assert_eq!(c.buf.capacity(), 1024);

c.i2c.done();
}
}

0 comments on commit 2f1b730

Please sign in to comment.