diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-04-05 18:40:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-05 18:40:24 +0200 |
commit | 2aed322dd507a8568b6ee6f4897e9a8e3220f763 (patch) | |
tree | e9a45c0b7688a9881ea9ce132b92554ef2955ad6 /op_crates/webgpu/error.rs | |
parent | 284e6c303956e8ca20af63b4ecc045438a260fe6 (diff) |
refactor: convert ops to use serde_v8 (#10009)
This commit rewrites most of the ops to use "serde_v8" instead
of "json" serialization.
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 { |