Skip to content

Commit

Permalink
refactor/export: handle import via prelude module [SKIP_CHANGELOG]
Browse files Browse the repository at this point in the history
REFERENCES #40
  • Loading branch information
hobofan committed Feb 4, 2016
1 parent 5ee93cd commit 60c1a39
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -87,7 +87,7 @@ to your Cargo manifest.
```rust
extern crate collenchyma as co;
extern crate collenchyma_nn as nn;
use co::*;
use co::prelude::*;
use nn::*;

fn write_to_memory<T: Copy>(mem: &mut MemoryType, data: &[T]) {
Expand Down
34 changes: 33 additions & 1 deletion src/lib.rs
Expand Up @@ -74,7 +74,7 @@
//! ```ignore
//! extern crate collenchyma as co;
//! extern crate collenchyma_nn as nn;
//! use co::*;
//! use co::prelude::*;
//! use nn::*;
//!
//! fn write_to_memory<T: Copy>(mem: &mut MemoryType, data: &[T]) {
Expand Down Expand Up @@ -171,6 +171,7 @@ pub mod binary;
pub mod error;
pub mod plugin;

// These will be exported with the prelude.
pub use backend::*;
pub use device::{IDevice, DeviceType};
pub use hardware::{IHardware, HardwareType};
Expand All @@ -183,3 +184,34 @@ pub use frameworks::Native;
pub use frameworks::Cuda;
#[cfg(feature = "opencl")]
pub use frameworks::OpenCL;

// These should only be imported with caution, since they are likely
// to create a namespace collision.
pub use error::Error;

/// A module meant to be glob imported when using Collenchyma.
///
/// For instance:
///
/// ```
/// use collenchyma::prelude::*;
/// ```
///
/// This module contains several important traits that provide many
/// of the convenience methods in Collenchyma, as well as most important types.
/// Another type that is often needed but is likely to cause a name collision
/// when imported is `collenchyma::Error`.
pub mod prelude {
pub use backend::*;
pub use device::{IDevice, DeviceType};
pub use hardware::{IHardware, HardwareType};
pub use framework::IFramework;
pub use memory::{IMemory, MemoryType};
pub use tensor::{SharedTensor, TensorDesc, ITensorDesc, IntoTensorDesc};
#[cfg(feature = "native")]
pub use frameworks::Native;
#[cfg(feature = "cuda")]
pub use frameworks::Cuda;
#[cfg(feature = "opencl")]
pub use frameworks::OpenCL;
}
2 changes: 1 addition & 1 deletion tests/backend_specs.rs
Expand Up @@ -6,7 +6,7 @@ mod backend_spec {
#[cfg(feature = "native")]
mod native {
use std::rc::Rc;
use co::*;
use co::prelude::*;

#[test]
fn it_can_create_default_backend() {
Expand Down
2 changes: 1 addition & 1 deletion tests/framework_cuda_specs.rs
Expand Up @@ -4,7 +4,7 @@ extern crate libc;
#[cfg(test)]
#[cfg(feature = "cuda")]
mod framework_cuda_spec {
use co::*;
use co::prelude::*;
use co::frameworks::cuda::memory::*;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/framework_native_specs.rs
Expand Up @@ -3,7 +3,7 @@ extern crate collenchyma as co;
#[cfg(test)]
#[cfg(feature = "native")]
mod framework_native_spec {
use co::*;
use co::prelude::*;

#[test]
fn it_works() {
Expand Down
2 changes: 1 addition & 1 deletion tests/framework_opencl_specs.rs
Expand Up @@ -4,7 +4,7 @@ extern crate libc;
#[cfg(test)]
#[cfg(feature = "opencl")]
mod framework_opencl_spec {
use co::*;
use co::prelude::*;
use co::frameworks::opencl::memory::*;
use co::frameworks::opencl::queue::*;

Expand Down
2 changes: 1 addition & 1 deletion tests/hardware_specs.rs
Expand Up @@ -4,7 +4,7 @@ extern crate libc;
#[cfg(test)]
#[cfg(feature = "opencl")]
mod hardware_spec {
use co::*;
use co::prelude::*;
use co::frameworks::opencl::Device;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/shared_memory_specs.rs
Expand Up @@ -3,7 +3,7 @@ extern crate libc;

#[cfg(test)]
mod shared_memory_spec {
use co::*;
use co::prelude::*;

fn write_to_memory<T: Copy>(mem: &mut MemoryType, data: &[T]) {
match mem {
Expand Down
2 changes: 1 addition & 1 deletion tests/tensor_specs.rs
Expand Up @@ -2,7 +2,7 @@ extern crate collenchyma as co;

#[cfg(test)]
mod tensor_spec {
use co::*;
use co::prelude::*;

#[test]
fn it_returns_correct_tensor_desc_stride() {
Expand Down

0 comments on commit 60c1a39

Please sign in to comment.