Skip to main content

kira/
error.rs

1use std::{
2	error::Error,
3	fmt::{Display, Formatter},
4};
5
6/// Errors that can occur when playing a sound.
7#[derive(Debug)]
8pub enum PlaySoundError<E> {
9	/// Could not play a sound because the maximum number of sounds has been reached.
10	SoundLimitReached,
11	/// An error occurred when initializing the sound.
12	IntoSoundError(E),
13}
14
15impl<E> Display for PlaySoundError<E> {
16	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
17		match self {
18			PlaySoundError::SoundLimitReached => f.write_str(
19				"Could not play a sound because the maximum number of sounds has been reached.",
20			),
21			PlaySoundError::IntoSoundError(_) => {
22				f.write_str("An error occurred when initializing the sound.")
23			}
24		}
25	}
26}
27
28impl<E: std::fmt::Debug> Error for PlaySoundError<E> {}
29
30/// An error that is returned when a resource cannot be added because the
31/// maximum capacity for that resource has been reached.
32///
33/// You can adjust these capacities using [`Capacities`](crate::Capacities).
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
35pub struct ResourceLimitReached;
36
37impl Display for ResourceLimitReached {
38	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39		f.write_str(
40			"Could not add a resource because the maximum capacity for that resource has been reached",
41		)
42	}
43}
44
45impl Error for ResourceLimitReached {}