1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::las::laszip::{CompressorType, LazItemType};
use std::fmt;

/// Errors of this crate
#[derive(Debug)]
pub enum LasZipError {
    /// The Laz item it not known
    UnknownLazItem(u16),
    /// The compression version used for the item is not supported
    UnsupportedLazItemVersion(LazItemType, u16),
    /// The type of compressor used is not known
    UnknownCompressorType(u16),
    /// The type of compressor exists but it is not supported
    UnsupportedCompressorType(CompressorType),
    /// Wrapper around and io error from the std lib
    IoError(std::io::Error),
    BufferLenNotMultipleOfPointSize {
        buffer_len: usize,
        point_size: usize,
    },
}

impl From<std::io::Error> for LasZipError {
    fn from(e: std::io::Error) -> Self {
        LasZipError::IoError(e)
    }
}

impl fmt::Display for LasZipError {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        match self {
            LasZipError::UnknownLazItem(t) => write!(f, "Item with type code: {} is unknown", t),
            LasZipError::UnsupportedLazItemVersion(item_type, version) => write!(
                f,
                "Item {:?} with compression version: {} is not supported",
                item_type, version
            ),
            LasZipError::UnknownCompressorType(compressor_type) => {
                write!(f, "Compressor type {} is not valid", compressor_type)
            }
            LasZipError::UnsupportedCompressorType(compressor_type) => {
                write!(f, "Compressor type {:?} is not supported", compressor_type)
            }
            LasZipError::IoError(e) => write!(f, "IoError: {}", e),

            LasZipError::BufferLenNotMultipleOfPointSize {
                buffer_len: bl,
                point_size: ps,
            } => write!(
                f,
                "The len of the buffer ({}) is not a multiple of the point size {}",
                bl, ps
            ),
        }
    }
}