Skip to content

Commit

Permalink
Auto merge of #41 - autumnai:fix/object-saftey, r=hobofan
Browse files Browse the repository at this point in the history
fix/backend: fix broken object saftey of IBackend [SKIP_CHANGELOG]
  • Loading branch information
homu committed Feb 4, 2016
2 parents f704817 + 11db83c commit 5ee93cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/backend.rs
Expand Up @@ -102,7 +102,7 @@ pub trait IBackend {
fn device(&self) -> &DeviceType;

/// Try to create a default backend.
fn default() -> Result<Backend<Self::F>, Error> {
fn default() -> Result<Backend<Self::F>, Error> where Self: Sized {
let hw_framework = Self::F::new();
let hardwares = hw_framework.hardwares();
let framework = Self::F::new(); // dirty dirty hack to get around borrowing
Expand Down
15 changes: 15 additions & 0 deletions tests/backend_specs.rs
Expand Up @@ -5,12 +5,27 @@ extern crate libc;
mod backend_spec {
#[cfg(feature = "native")]
mod native {
use std::rc::Rc;
use co::*;

#[test]
fn it_can_create_default_backend() {
assert!(Backend::<Native>::default().is_ok());
}

#[test]
fn it_can_use_ibackend_trait_object() {
let framework = Native::new();
let hardwares = framework.hardwares().to_vec();
let backend_config = BackendConfig::new(framework, &hardwares);
let backend = Rc::new(Backend::new(backend_config).unwrap());
use_ibackend(backend);
}

fn use_ibackend<B: IBackend>(backend: Rc<B>) {
let backend: Rc<IBackend<F=B::F>> = backend.clone();
backend.device();
}
}

#[cfg(feature = "cuda")]
Expand Down

0 comments on commit 5ee93cd

Please sign in to comment.