use std::fmt;
pub type Result<T> = std::result::Result<T, SyphonError>;
#[derive(Debug, Clone)]
pub enum SyphonError {
NotAvailable,
FrameworkNotFound(String),
CreateFailed(String),
ServerNotFound(String),
AmbiguousServerName(String),
InvalidParameter(String),
PublishFailed(String),
ReceiveFailed(String),
ObjcException,
LockFailed,
InvalidFrame,
IOSurfaceError(u32),
TextureError(String),
Other(String),
}
impl fmt::Display for SyphonError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SyphonError::NotAvailable => {
write!(f, "Syphon is not available on this platform")
}
SyphonError::FrameworkNotFound(msg) => {
write!(f, "Syphon framework not found: {}", msg)
}
SyphonError::CreateFailed(msg) => {
write!(f, "Failed to create Syphon object: {}", msg)
}
SyphonError::ServerNotFound(name) => {
write!(f, "Syphon server '{}' not found", name)
}
SyphonError::AmbiguousServerName(name) => {
write!(f, "Multiple Syphon servers named '{}' — use connect_by_info() with a UUID for precise selection", name)
}
SyphonError::InvalidParameter(msg) => {
write!(f, "Invalid parameter: {}", msg)
}
SyphonError::PublishFailed(msg) => {
write!(f, "Failed to publish frame: {}", msg)
}
SyphonError::ReceiveFailed(msg) => {
write!(f, "Failed to receive frame: {}", msg)
}
SyphonError::ObjcException => {
write!(f, "Objective-C exception was thrown")
}
SyphonError::LockFailed => {
write!(f, "Failed to lock/unlock IOSurface")
}
SyphonError::InvalidFrame => {
write!(f, "Invalid frame received")
}
SyphonError::IOSurfaceError(code) => {
write!(f, "IOSurface error: {}", code)
}
SyphonError::TextureError(msg) => {
write!(f, "Texture error: {}", msg)
}
SyphonError::Other(msg) => {
write!(f, "{}", msg)
}
}
}
}
impl std::error::Error for SyphonError {}
impl From<std::ffi::NulError> for SyphonError {
fn from(e: std::ffi::NulError) -> Self {
SyphonError::InvalidParameter(format!("String contains null byte: {}", e))
}
}
impl From<std::io::Error> for SyphonError {
fn from(e: std::io::Error) -> Self {
SyphonError::Other(format!("IO error: {}", e))
}
}