use native::NativeMemory;
use opencl::OpenCLMemory;
#[derive(Debug)]
pub enum Memory<T> {
Native(NativeMemory<T>),
OpenCL(OpenCLMemory),
}
impl<T> Memory<T> {
pub fn as_native(&self) -> Option<&NativeMemory<T>> {
match *self {
Memory::Native(ref native) => Some(native),
_ => None
}
}
pub fn as_mut_native(&mut self) -> Option<&mut NativeMemory<T>> {
match *self {
Memory::Native(ref mut native) => Some(native),
_ => None
}
}
pub unsafe fn as_native_unchecked(&self) -> &NativeMemory<T> {
match *self {
Memory::Native(ref native) => native,
_ => unreachable!()
}
}
pub unsafe fn as_mut_native_unchecked(&mut self) -> &mut NativeMemory<T> {
match *self {
Memory::Native(ref mut native) => native,
_ => unreachable!()
}
}
pub fn into_native(self) -> Option<NativeMemory<T>> {
match self {
Memory::Native(native) => Some(native),
_ => None
}
}
pub fn as_opencl(&self) -> Option<&OpenCLMemory> {
match *self {
Memory::OpenCL(ref opencl) => Some(opencl),
_ => None
}
}
pub fn as_mut_opencl(&mut self) -> Option<&mut OpenCLMemory> {
match *self {
Memory::OpenCL(ref mut opencl) => Some(opencl),
_ => None
}
}
pub unsafe fn as_opencl_unchecked(&self) -> &OpenCLMemory {
match *self {
Memory::OpenCL(ref opencl) => opencl,
_ => unreachable!()
}
}
}