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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::{
	error::Error,
	fmt::{Display, Formatter},
};

use crate::CommandError;

/// Errors that can occur when creating a emitter.
#[derive(Debug)]
#[non_exhaustive]
pub enum AddEmitterError {
	/// Could not add a emitter because the maximum number of emitters has been reached.
	EmitterLimitReached,
	/// An error occurred when sending a command to the audio thread.
	CommandError(CommandError),
}

impl Display for AddEmitterError {
	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
		match self {
			AddEmitterError::EmitterLimitReached => f.write_str(
				"Could not add a emitter because the maximum number of emitters has been reached.",
			),
			AddEmitterError::CommandError(error) => error.fmt(f),
		}
	}
}

impl Error for AddEmitterError {
	fn source(&self) -> Option<&(dyn Error + 'static)> {
		match self {
			AddEmitterError::CommandError(error) => Some(error),
			_ => None,
		}
	}
}

impl From<CommandError> for AddEmitterError {
	fn from(v: CommandError) -> Self {
		Self::CommandError(v)
	}
}

/// Errors that can occur when creating a listener.
#[derive(Debug)]
#[non_exhaustive]
pub enum AddListenerError {
	/// Could not add a listener because the maximum number of listeners has been reached.
	ListenerLimitReached,
	/// An error occurred when sending a command to the audio thread.
	CommandError(CommandError),
}

impl Display for AddListenerError {
	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
		match self {
			AddListenerError::ListenerLimitReached => f.write_str(
				"Could not add a listener because the maximum number of listeners has been reached.",
			),
			AddListenerError::CommandError(error) => error.fmt(f),
		}
	}
}

impl Error for AddListenerError {
	fn source(&self) -> Option<&(dyn Error + 'static)> {
		match self {
			AddListenerError::CommandError(error) => Some(error),
			_ => None,
		}
	}
}

impl From<CommandError> for AddListenerError {
	fn from(v: CommandError) -> Self {
		Self::CommandError(v)
	}
}