diff options
author | TrueDoctor <dennis@kobert.dev> | 2019-06-22 00:03:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-22 00:03:37 +0200 |
commit | 8b2040eb93e8e4355c8f357b775dedcffafff3dc (patch) | |
tree | 0b2c4724f0c75d09ee8b86f397bf6602a899e825 /webhogg/wasm/src/error.rs | |
parent | 9e9c1c822a64c0a65033b7eed07ea661a385cecc (diff) | |
parent | 5522731ec4de8741f923b339ca942f8aaff2a338 (diff) |
Merge pull request #39 from TrueDoctor/game_server_refactor
Game server refactor
Diffstat (limited to 'webhogg/wasm/src/error.rs')
-rw-r--r-- | webhogg/wasm/src/error.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/webhogg/wasm/src/error.rs b/webhogg/wasm/src/error.rs new file mode 100644 index 0000000..fbb6bf8 --- /dev/null +++ b/webhogg/wasm/src/error.rs @@ -0,0 +1,36 @@ +use std::error::Error; + +#[derive(Debug)] +pub enum WasmError { + WebGl2ContextCreation(String), + Shader(String), + WebGlBuffer(String), +} + +impl std::fmt::Display for WasmError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + write!(f, "{}: {}", self.name(), self.description()) + } +} + +impl Error for WasmError { + fn description(&self) -> &str { + match self { + WasmError::WebGl2ContextCreation(msg) => msg, + WasmError::Shader(msg) => msg, + WasmError::WebGlBuffer(msg) => msg, + } + } + + fn source(&self) -> Option<&'static dyn Error> { None } +} + +impl WasmError { + pub fn name(&self) -> &str { + match self { + WasmError::WebGl2ContextCreation(_) => "WebGl2ContextCreationError", + WasmError::Shader(_) => "ShaderError", + WasmError::WebGlBuffer(_) => "WebGlBufferError", + } + } +} |