This commit is contained in:
parent
28f0bd5903
commit
4ccbd57ba8
3 changed files with 9 additions and 7 deletions
|
|
@ -60,6 +60,7 @@ pub enum TryFromPacketError {
|
|||
/// Some provided text was not valid UTF-8.
|
||||
#[error(transparent)]
|
||||
InvalidUtf8(#[from] std::string::FromUtf8Error),
|
||||
/// The bitmap contained in the payload could not be loaded
|
||||
#[error(transparent)]
|
||||
LoadBitmapFailed(#[from] LoadBitmapError),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ impl Bitmap {
|
|||
}
|
||||
|
||||
/// Iterate over all rows in [Bitmap] top to bottom.
|
||||
pub fn iter_rows(&self) -> IterRows {
|
||||
pub fn iter_rows(&self) -> impl Iterator<Item = &BitSlice<u8, Msb0>> {
|
||||
IterRows {
|
||||
bitmap: self,
|
||||
row: 0,
|
||||
|
|
@ -258,7 +258,7 @@ impl From<&Bitmap> for ValueGrid<bool> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct IterRows<'t> {
|
||||
struct IterRows<'t> {
|
||||
bitmap: &'t Bitmap,
|
||||
row: usize,
|
||||
}
|
||||
|
|
@ -278,10 +278,13 @@ impl<'t> Iterator for IterRows<'t> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Errors that can happen when loading a bitmap.
|
||||
#[derive(thiserror::Error, Debug, PartialEq)]
|
||||
pub enum LoadBitmapError {
|
||||
/// The provided width is not divisible by 8.
|
||||
#[error("The provided width is not divisible by 8.")]
|
||||
InvalidWidth,
|
||||
/// The provided data has an incorrect size for the provided dimensions.
|
||||
#[error(
|
||||
"The provided data has an incorrect size for the provided dimensions."
|
||||
)]
|
||||
|
|
|
|||
|
|
@ -140,11 +140,9 @@ impl CharGrid {
|
|||
bytes: Vec<u8>,
|
||||
) -> Result<CharGrid, LoadUtf8Error> {
|
||||
let s: Vec<char> = String::from_utf8(bytes)?.chars().collect();
|
||||
Ok(CharGrid::load(width, height, &s).ok_or(
|
||||
LoadUtf8Error::TryLoadError(
|
||||
TryLoadValueGridError::InvalidDimensions,
|
||||
),
|
||||
)?)
|
||||
CharGrid::load(width, height, &s).ok_or(LoadUtf8Error::TryLoadError(
|
||||
TryLoadValueGridError::InvalidDimensions,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue