1 use thiserror::Error; 2 3 pub type Result<T> = std::result::Result<T, Error>; 4 5 #[derive(Error, Debug, PartialEq)] 6 #[non_exhaustive] 7 pub enum Error { 8 #[error("Invalid Parent RTCP Reader")] 9 ErrInvalidParentRtcpReader, 10 #[error("Invalid Parent RTP Reader")] 11 ErrInvalidParentRtpReader, 12 #[error("Invalid Next RTP Writer")] 13 ErrInvalidNextRtpWriter, 14 #[error("Invalid CloseRx Channel")] 15 ErrInvalidCloseRx, 16 #[error("Invalid PacketRx Channel")] 17 ErrInvalidPacketRx, 18 #[error("IO EOF")] 19 ErrIoEOF, 20 #[error("Buffer is too short")] 21 ErrShortBuffer, 22 #[error("Invalid buffer size")] 23 ErrInvalidSize, 24 25 #[error("{0}")] 26 Srtp(#[from] srtp::Error), 27 #[error("{0}")] 28 Rtcp(#[from] rtcp::Error), 29 #[error("{0}")] 30 Rtp(#[from] rtp::Error), 31 #[error("{0}")] 32 Util(#[from] util::Error), 33 34 #[error("{0}")] 35 Other(String), 36 } 37 38 /// flatten_errs flattens multiple errors into one 39 pub fn flatten_errs(errs: Vec<Error>) -> Result<()> { 40 if errs.is_empty() { 41 Ok(()) 42 } else { 43 let errs_strs: Vec<String> = errs.into_iter().map(|e| e.to_string()).collect(); 44 Err(Error::Other(errs_strs.join("\n"))) 45 } 46 } 47