aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/x11/xdisplay.rs
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2015-09-20 08:42:32 +0200
committerPierre Krieger <pierre.krieger1708@gmail.com>2015-09-20 08:42:32 +0200
commitb9a4f5fbe90a94fbca2e6816b92a129dabfe81fd (patch)
tree0a825a6212ea192840276d7bb4214322ceb4d209 /src/api/x11/xdisplay.rs
parent27385894ac81d28dd984764c65914ca512043c16 (diff)
downloadglutin-b9a4f5fbe90a94fbca2e6816b92a129dabfe81fd.tar.gz
glutin-b9a4f5fbe90a94fbca2e6816b92a129dabfe81fd.zip
Err when a X connection cannot be created instead of panicking
Diffstat (limited to 'src/api/x11/xdisplay.rs')
-rw-r--r--src/api/x11/xdisplay.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/api/x11/xdisplay.rs b/src/api/x11/xdisplay.rs
index c960c00..d48d947 100644
--- a/src/api/x11/xdisplay.rs
+++ b/src/api/x11/xdisplay.rs
@@ -1,4 +1,6 @@
use std::ptr;
+use std::fmt;
+use std::error::Error;
use std::ffi::CString;
use libc;
@@ -21,10 +23,6 @@ pub struct XConnection {
unsafe impl Send for XConnection {}
unsafe impl Sync for XConnection {}
-/// Error returned if this system doesn't have XLib or can't create an X connection.
-#[derive(Copy, Clone, Debug)]
-pub struct XNotSupported;
-
impl XConnection {
pub fn new() -> Result<XConnection, XNotSupported> {
// opening the libraries
@@ -104,3 +102,19 @@ impl Drop for XConnection {
unsafe { (self.xlib.XCloseDisplay)(self.display) };
}
}
+
+/// Error returned if this system doesn't have XLib or can't create an X connection.
+#[derive(Copy, Clone, Debug)]
+pub struct XNotSupported;
+
+impl Error for XNotSupported {
+ fn description(&self) -> &str {
+ "The X windowing system could not be initialized"
+ }
+}
+
+impl fmt::Display for XNotSupported {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ formatter.write_str(self.description())
+ }
+}