diff options
Diffstat (limited to 'op_crates/webgpu/error.rs')
-rw-r--r-- | op_crates/webgpu/error.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/op_crates/webgpu/error.rs b/op_crates/webgpu/error.rs index 15036512e..57e2e675f 100644 --- a/op_crates/webgpu/error.rs +++ b/op_crates/webgpu/error.rs @@ -1,6 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; +use deno_core::ResourceId; use serde::Serialize; +use std::convert::From; use std::fmt; use wgpu_core::binding_model::CreateBindGroupError; use wgpu_core::binding_model::CreateBindGroupLayoutError; @@ -28,6 +30,45 @@ use wgpu_core::resource::CreateTextureError; use wgpu_core::resource::CreateTextureViewError; #[derive(Serialize)] +pub struct WebGpuResult { + pub rid: Option<ResourceId>, + pub err: Option<WebGpuError>, +} + +impl WebGpuResult { + pub fn rid(rid: ResourceId) -> Self { + Self { + rid: Some(rid), + err: None, + } + } + + pub fn rid_err<T: Into<WebGpuError>>( + rid: ResourceId, + err: Option<T>, + ) -> Self { + Self { + rid: Some(rid), + err: err.map(|e| e.into()), + } + } + + pub fn maybe_err<T: Into<WebGpuError>>(err: Option<T>) -> Self { + Self { + rid: None, + err: err.map(|e| e.into()), + } + } + + pub fn empty() -> Self { + Self { + rid: None, + err: None, + } + } +} + +#[derive(Serialize)] #[serde(tag = "type", content = "value")] #[serde(rename_all = "kebab-case")] pub enum WebGpuError { |