chore(hal,core): use core::{error::Error,format} instead of std

This allows `wgpu-hal` to be used in `no_std` environments, except that
currently, only the `noop` backend supports `no_std`.
In the future, `cfg(all(gles, webgl))` should also be `no_std`, but that
requires further work.

Co-Authored_by: Kevin Reid <kpreid@switchb.org>
This commit is contained in:
Erich Gubler
2025-02-26 16:30:34 -05:00
parent f234ff27ab
commit 6f0c2434a7
6 changed files with 9 additions and 10 deletions

View File

@@ -303,7 +303,7 @@ impl fmt::Display for DeviceMismatch {
}
}
impl std::error::Error for DeviceMismatch {}
impl core::error::Error for DeviceMismatch {}
#[derive(Clone, Debug, Error)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

View File

@@ -1,6 +1,5 @@
use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec};
use core::fmt;
use std::error::Error; // TODO(https://github.com/gfx-rs/wgpu/issues/6826): use core::error after MSRV bump
use core::{error::Error, fmt};
use thiserror::Error;

View File

@@ -1,6 +1,7 @@
//! RenderDoc integration - <https://renderdoc.org/>
#![cfg_attr(not(any(feature = "gles", feature = "vulkan")), allow(dead_code))]
use alloc::format;
use alloc::string::String;
use core::{ffi, ptr};

View File

@@ -240,8 +240,9 @@
extern crate alloc;
extern crate wgpu_types as wgt;
// TODO(https://github.com/gfx-rs/wgpu/issues/6826): disable std except on noop and gles-WebGL.
// Requires Rust 1.81 for core::error::Error.
// Each of these backends needs `std` in some fashion; usually `std::thread` functions.
// TODO(https://github.com/gfx-rs/wgpu/issues/6826): gles-WebGL backend should be made no-std
#[cfg(any(dx12, gles, metal, vulkan))]
#[macro_use]
extern crate std;
@@ -290,12 +291,12 @@ use alloc::boxed::Box;
use alloc::{borrow::Cow, string::String, sync::Arc, vec::Vec};
use core::{
borrow::Borrow,
error::Error,
fmt,
num::NonZeroU32,
ops::{Range, RangeInclusive},
ptr::NonNull,
};
use std::error::Error; // TODO(https://github.com/gfx-rs/wgpu/issues/6826): use core::error after MSRV bump
use bitflags::bitflags;
use parking_lot::Mutex;

View File

@@ -1,6 +1,5 @@
use alloc::{boxed::Box, string::String, vec, vec::Vec};
use core::fmt;
use std::error; // TODO(https://github.com/gfx-rs/wgpu/issues/6826): use core::error after MSRV bump
use core::{error, fmt};
use parking_lot::Mutex;
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};

View File

@@ -1,5 +1,4 @@
use core::fmt;
use std::error; // TODO(https://github.com/gfx-rs/wgpu/issues/6826): use core::error after MSRV bump
use core::{error, fmt};
use std::thread;
use crate::*;