aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-11-05 16:42:18 +0100
committerTomaka17 <pierre.krieger1708@gmail.com>2014-11-05 16:42:18 +0100
commit584bb3e7df751d55aad189eacd85b1cd6c5aa5c5 (patch)
tree91711433533faa6b44f62eb752d54c0a39129e12 /src/lib.rs
parent7ce851dad9102c28ee2fd372ed9fd62e73364da9 (diff)
downloadglutin-584bb3e7df751d55aad189eacd85b1cd6c5aa5c5.tar.gz
glutin-584bb3e7df751d55aad189eacd85b1cd6c5aa5c5.zip
Use a proper error type for window creation
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a976da5..3c8b939 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -70,6 +70,20 @@ compile_error!("Only the `windows`, `linux` and `macos` platforms are supported"
#[cfg(feature = "window")]
pub struct MonitorID(winimpl::MonitorID);
+/// Error that can happen while creating a window or a headless renderer.
+#[deriving(Clone, Show, PartialEq, Eq)]
+pub enum CreationError {
+ OsError(String),
+}
+
+impl std::error::Error for CreationError {
+ fn description(&self) -> &str {
+ match self {
+ &OsError(ref text) => text.as_slice(),
+ }
+ }
+}
+
/// Object that allows you to build windows.
#[cfg(feature = "window")]
pub struct WindowBuilder {
@@ -143,7 +157,7 @@ impl WindowBuilder {
///
/// Error should be very rare and only occur in case of permission denied, incompatible system,
/// out of memory, etc.
- pub fn build(mut self) -> Result<Window, String> {
+ pub fn build(mut self) -> Result<Window, CreationError> {
// resizing the window to the dimensions of the monitor when fullscreen
if self.dimensions.is_none() && self.monitor.is_some() {
self.dimensions = Some(self.monitor.as_ref().unwrap().get_dimensions())
@@ -189,7 +203,7 @@ impl HeadlessRendererBuilder {
///
/// Error should be very rare and only occur in case of permission denied, incompatible system,
/// out of memory, etc.
- pub fn build(self) -> Result<HeadlessContext, String> {
+ pub fn build(self) -> Result<HeadlessContext, CreationError> {
winimpl::HeadlessContext::new(self).map(|w| HeadlessContext { context: w })
}
}
@@ -238,7 +252,7 @@ impl Window {
/// out of memory, etc.
#[inline]
#[cfg(feature = "window")]
- pub fn new() -> Result<Window, String> {
+ pub fn new() -> Result<Window, CreationError> {
let builder = WindowBuilder::new();
builder.build()
}