From b9a4f5fbe90a94fbca2e6816b92a129dabfe81fd Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sun, 20 Sep 2015 08:42:32 +0200 Subject: Err when a X connection cannot be created instead of panicking --- src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 94cd445..24913fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,11 +106,12 @@ pub trait GlContext { } /// Error that can happen while creating a window or a headless renderer. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Debug)] pub enum CreationError { OsError(String), /// TODO: remove this error NotSupported, + NoBackendAvailable(Box), RobustnessNotSupported, OpenGlVersionNotSupported, NoAvailablePixelFormat, @@ -121,6 +122,7 @@ impl CreationError { match *self { CreationError::OsError(ref text) => &text, CreationError::NotSupported => "Some of the requested attributes are not supported", + CreationError::NoBackendAvailable(_) => "No backend is available", CreationError::RobustnessNotSupported => "You requested robustness, but it is \ not supported.", CreationError::OpenGlVersionNotSupported => "The requested OpenGL version is not \ @@ -141,6 +143,13 @@ impl std::error::Error for CreationError { fn description(&self) -> &str { self.to_string() } + + fn cause(&self) -> Option<&std::error::Error> { + match *self { + CreationError::NoBackendAvailable(ref err) => Some(&**err), + _ => None + } + } } /// Error that can happen when manipulating an OpenGL context. -- cgit v1.2.3