reaper_medium/
errors.rs

1use derive_more::*;
2use std::fmt::{Debug, Display};
3
4/// An error which can occur when executing a REAPER function.
5///
6/// This is not an error caused by *reaper-rs*, but one reported by REAPER itself.
7/// The error message is not very specific most of the time because REAPER functions usually don't
8/// give information about the cause of the error.
9#[derive(Copy, Clone, Eq, PartialEq, Debug, Display, Error)]
10#[display(fmt = "REAPER function failed: {}", message)]
11pub struct ReaperFunctionError {
12    message: &'static str,
13}
14
15impl ReaperFunctionError {
16    pub(crate) fn new(message: &'static str) -> ReaperFunctionError {
17        ReaperFunctionError { message }
18    }
19}
20
21pub(crate) type ReaperFunctionResult<T> = Result<T, ReaperFunctionError>;
22
23/// An error which can occur when trying to convert a low-level type to a medium-level type.
24///
25/// This error is caused by *reaper-rs*, not by REAPER itself.
26#[derive(Debug, Clone, Eq, PartialEq, Display)]
27#[display(fmt = "conversion from raw value [{}] failed: {}", raw_value, message)]
28pub struct TryFromRawError<R> {
29    message: &'static str,
30    raw_value: R,
31}
32
33impl<R: Copy> TryFromRawError<R> {
34    pub(crate) fn new(message: &'static str, raw_value: R) -> TryFromRawError<R> {
35        TryFromRawError { message, raw_value }
36    }
37}
38
39impl<R: Copy + Display + Debug> std::error::Error for TryFromRawError<R> {}