industrial_io/errors.rs
1// libiio-sys/src/errors.rs
2//
3// Copyright (c) 2018-2025, Frank Pagliughi
4//
5// Licensed under the MIT license:
6// <LICENSE or http://opensource.org/licenses/MIT>
7// This file may not be copied, modified, or distributed except according
8// to those terms.
9//
10//!
11//! Error definitions for the Industrial I/O Library.
12
13use std::{ffi, io};
14use thiserror::Error;
15
16/// The Error type for the IIO library
17#[derive(Error, Debug)]
18pub enum Error {
19 /// A low-level I/O error
20 #[error("{0}")]
21 Io(#[from] io::Error),
22 /// An unexpected NUL value returned from the C library.
23 #[error("{0}")]
24 NulError(#[from] ffi::NulError),
25 /// A low-level Unix-style error
26 #[error("{0}")]
27 Nix(#[from] nix::Error),
28 /// An error converting a value to/from a string representation.
29 #[error("String conversion error")]
30 StringConversionError,
31 /// The wrong data type used in an operation
32 #[error("Wrong data type")]
33 WrongDataType,
34 /// The size of a data or return value was different than expected.
35 #[error("Bad return size")]
36 BadReturnSize,
37 /// A device or channel index did not find a requested object
38 #[error("Invalid index")]
39 InvalidIndex,
40 /// A generic error with a string explanation
41 #[error("{0}")]
42 General(String),
43}
44
45/// The default result type for the IIO library
46pub type Result<T> = std::result::Result<T, Error>;