pub struct DeviceHandle<P: PhantomDevice> { /* private fields */ }Expand description
Type-safe device handle with phantom device information
This wrapper provides compile-time device type safety for device operations. The phantom type parameter carries device information at the type level.
§Examples
ⓘ
use torsh_core::device::{DeviceHandle, PhantomCpu, PhantomCuda};
// CPU device handle
let cpu_handle = DeviceHandle::<PhantomCpu>::new(cpu_device);
// CUDA device handle with index 0
let cuda_handle = DeviceHandle::<PhantomCuda<0>>::new(cuda_device);
// Compile-time device type checking
assert!(cpu_handle.is_cpu());
assert!(cuda_handle.is_gpu());Implementations§
Source§impl<P: PhantomDevice> DeviceHandle<P>
impl<P: PhantomDevice> DeviceHandle<P>
Sourcepub fn new(device: Box<dyn Device>) -> Result<Self, TorshError>
pub fn new(device: Box<dyn Device>) -> Result<Self, TorshError>
Create a new device handle with phantom type information
Sourcepub unsafe fn new_unchecked(device: Box<dyn Device>) -> Self
pub unsafe fn new_unchecked(device: Box<dyn Device>) -> Self
Create an unchecked device handle (unsafe)
§Safety
The caller must ensure that the device type matches the phantom type.
Sourcepub fn device_mut(&mut self) -> &mut dyn Device
pub fn device_mut(&mut self) -> &mut dyn Device
Get the underlying device mutably
Sourcepub fn phantom_device_type() -> DeviceType
pub fn phantom_device_type() -> DeviceType
Get the phantom device type
Sourcepub fn cast<Q: PhantomDevice>(
self,
) -> Result<DeviceHandle<Q>, (Self, TorshError)>
pub fn cast<Q: PhantomDevice>( self, ) -> Result<DeviceHandle<Q>, (Self, TorshError)>
Convert to a different phantom device type (with runtime check)
Sourcepub unsafe fn cast_unchecked<Q: PhantomDevice>(self) -> DeviceHandle<Q>
pub unsafe fn cast_unchecked<Q: PhantomDevice>(self) -> DeviceHandle<Q>
Convert to a different phantom device type (unsafe, no runtime check)
§Safety
The caller must ensure that the device type matches the target phantom type.
Sourcepub fn into_device(self) -> Box<dyn Device>
pub fn into_device(self) -> Box<dyn Device>
Extract the underlying device, consuming the handle
Trait Implementations§
Source§impl<P: PhantomDevice> Clone for DeviceHandle<P>
impl<P: PhantomDevice> Clone for DeviceHandle<P>
Auto Trait Implementations§
impl<P> Freeze for DeviceHandle<P>
impl<P> !RefUnwindSafe for DeviceHandle<P>
impl<P> Send for DeviceHandle<P>
impl<P> Sync for DeviceHandle<P>
impl<P> Unpin for DeviceHandle<P>where
P: Unpin,
impl<P> UnsafeUnpin for DeviceHandle<P>
impl<P> !UnwindSafe for DeviceHandle<P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more