vigem_client/
error.rs

1use std::{error, fmt};
2
3/// ViGEm client errors.
4#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5#[non_exhaustive]
6pub enum Error {
7	/// There was an unexpected windows error.
8	///
9	/// See [System Error Codes](https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes) for more information.
10	WinError(u32),
11	/// The ViGEmBus Driver is not installed.
12	///
13	/// It can be installed from the [ViGEmBus](https://github.com/ViGEm/ViGEmBus) repository.
14	BusNotFound,
15	/// ViGEmBus was found, but accessing it returned an error.
16	BusAccessFailed(u32),
17	/// ViGEmBus was found, but it did not accept this client's version.
18	BusVersionMismatch,
19	/// There was no more room to allocate new targets.
20	NoFreeSlot,
21	// InvalidClient,
22	// InvalidTarget,
23	/// The target is already connected.
24	///
25	/// It is an error to try to plugin an already connected target.
26	AlreadyConnected,
27	/// The target is not plugged in.
28	NotPluggedIn,
29	/// The target is not ready.
30	///
31	/// After creating the desired controller, wait some time before the target is ready to accept updates.
32	/// This error is returned if a target is updated before it is ready.
33	TargetNotReady,
34	/// The user index is out of range.
35	///
36	/// In XInput the user index should be between 0 and 4 exclusive.
37	UserIndexOutOfRange,
38	/// The operation was aborted.
39	OperationAborted,
40}
41
42impl From<u32> for Error {
43	#[inline]
44	fn from(error: u32) -> Error {
45		Error::WinError(error)
46	}
47}
48
49impl fmt::Display for Error {
50	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51		match *self {
52			Error::WinError(err) => write!(f, "win error: {}", err),
53			Error::BusNotFound => f.write_str("bus not found"),
54			Error::BusAccessFailed(err) => write!(f, "bus access failed: {}", err),
55			Error::BusVersionMismatch => f.write_str("bus version mismatch"),
56			Error::NoFreeSlot => f.write_str("no free slot"),
57			Error::AlreadyConnected => f.write_str("already connected"),
58			Error::NotPluggedIn => f.write_str("not plugged in"),
59			Error::TargetNotReady => f.write_str("target not ready"),
60			Error::UserIndexOutOfRange => f.write_str("user index out of range"),
61			Error::OperationAborted => f.write_str("operation aborted"),
62		}
63	}
64}
65
66impl error::Error for Error {}