Skip to main content

GpuResultExt

Trait GpuResultExt 

Source
pub trait GpuResultExt<T> {
    // Required methods
    fn gpu_ctx(self, prefix: &str) -> Result<T, GpuError>;
    fn gpu_ctx_with<F>(self, f: F) -> Result<T, GpuError>
       where F: FnOnce(&dyn Display) -> String;
}
Expand description

Extension trait that attaches GPU-call context to any Result<T, E> whose error implements Display.

The two methods mirror the common shapes:

  • gpu_ctx appends ": {err}" to a caller-supplied prefix. This is the vastly dominant shape across the GPU layer (~235 sites in the original audit).
  • gpu_ctx_with takes a closure that receives the underlying error by &dyn Display and returns the full reason string. Use it when the reason is not a simple prefix: err concatenation (e.g. multi-line, or with the error embedded mid-message).

Cfg note: The trait and its blanket impl are gated to target_os = "linux" so the symbol literally does not exist on non-Linux targets. Every callsite is inside a #[cfg(target_os = "linux")] block that wraps CUDA driver / cuBLAS / cuSOLVER calls; on non-Linux those blocks are erased and the trait would have no users. Cfg-gating the definition means a warning-fix sweep running on non-Linux cannot see “unused” callsites because the trait itself is absent — the consuming use super::gpu_error::GpuResultExt; imports must therefore be #[cfg(target_os = "linux")] to match, and that cfg-symmetry is the architectural contract that prevents the drop-the-import regression that broke the Linux build in #302.

Required Methods§

Source

fn gpu_ctx(self, prefix: &str) -> Result<T, GpuError>

Map the error to GpuError::DriverCallFailed { reason: format!("{prefix}: {err}") }.

Source

fn gpu_ctx_with<F>(self, f: F) -> Result<T, GpuError>
where F: FnOnce(&dyn Display) -> String,

Map the error using a closure that takes the underlying error (as &dyn Display) and returns the reason string.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, E: Display> GpuResultExt<T> for Result<T, E>

Available on Linux only.
Source§

fn gpu_ctx(self, prefix: &str) -> Result<T, GpuError>

Source§

fn gpu_ctx_with<F>(self, f: F) -> Result<T, GpuError>
where F: FnOnce(&dyn Display) -> String,

Implementors§