diff --git a/crates/coremem/Cargo.toml b/crates/coremem/Cargo.toml index a35853a..a0faf20 100644 --- a/crates/coremem/Cargo.toml +++ b/crates/coremem/Cargo.toml @@ -44,7 +44,7 @@ spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu" } spirv-std-macros = { git = "https://github.com/EmbarkStudios/rust-gpu" } spirv_backend = { path = "../spirv_backend" } spirv_backend_runner = { path = "../spirv_backend_runner" } -coremem_cross = { path = "../cross", features = ["iter", "fmt", "serde"] } +coremem_cross = { path = "../cross", features = ["iter", "fmt", "serde", "std"] } [dev-dependencies] diff --git a/crates/cross/Cargo.toml b/crates/cross/Cargo.toml index 830ab88..8bd65f0 100644 --- a/crates/cross/Cargo.toml +++ b/crates/cross/Cargo.toml @@ -9,8 +9,9 @@ edition = "2021" serde = [ "dep:serde" ] fmt = [] iter = [] +std = [] [dependencies] serde = { version = "1.0", optional = true } # MIT or Apache 2.0 [dev-dependencies] -coremem_cross = { path = ".", default-features = false, features = ["iter", "fmt"] } +coremem_cross = { path = ".", default-features = false, features = ["iter", "fmt", "std"] } diff --git a/crates/cross/src/compound/list/mod.rs b/crates/cross/src/compound/list/mod.rs index b202f58..b24c270 100644 --- a/crates/cross/src/compound/list/mod.rs +++ b/crates/cross/src/compound/list/mod.rs @@ -240,6 +240,33 @@ where } } + +#[cfg(feature = "std")] +mod into_vec { + use super::*; + pub struct IntoVecOp; + impl FoldOp, Next> for IntoVecOp { + type Output = Vec; + fn feed(&mut self, mut prev: Vec, next: Next) -> Self::Output { + prev.push(next); + prev + } + } + pub trait IntoVec { + fn into_vec(self) -> Vec; + } + impl IntoVec for L + where + L: Fold, Output=Vec> + { + fn into_vec(self) -> Vec { + self.fold(IntoVecOp, Vec::new()) + } + } +} +#[cfg(feature = "std")] +pub use into_vec::{IntoVec, IntoVecOp}; + pub trait MapVisitor { type Output; fn map(&self, elem: V) -> Self::Output; @@ -502,6 +529,23 @@ mod test { assert_eq!(v.0, 24); } + #[test] + fn into_vec() { + let list = (3i32, 4i32, 5i32).into_list(); + assert_eq!(list.into_vec(), vec![3i32, 4, 5]); + } + + #[test] + fn into_vec_ref() { + let list = &(3i32, 4i32, 5i32).into_list(); + assert_eq!(list.into_vec(), vec![&3i32, &4, &5]); + } + + #[test] + fn into_vec_empty() { + assert_eq!(IntoVec::::into_vec(Empty::default()), vec![]); + } + #[test] fn sum() { let list = (3i32, 4i32, 5i32).into_list(); diff --git a/crates/cross/src/lib.rs b/crates/cross/src/lib.rs index c51c4ed..04cbec5 100644 --- a/crates/cross/src/lib.rs +++ b/crates/cross/src/lib.rs @@ -1,5 +1,5 @@ -#![no_std] #![feature(core_intrinsics)] +#![cfg_attr(not(feature = "std"), no_std)] pub mod compound; pub mod dim;