cross: list: add IntoVec
trait
This commit is contained in:
@@ -44,7 +44,7 @@ spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu" }
|
|||||||
spirv-std-macros = { git = "https://github.com/EmbarkStudios/rust-gpu" }
|
spirv-std-macros = { git = "https://github.com/EmbarkStudios/rust-gpu" }
|
||||||
spirv_backend = { path = "../spirv_backend" }
|
spirv_backend = { path = "../spirv_backend" }
|
||||||
spirv_backend_runner = { path = "../spirv_backend_runner" }
|
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]
|
[dev-dependencies]
|
||||||
|
@@ -9,8 +9,9 @@ edition = "2021"
|
|||||||
serde = [ "dep:serde" ]
|
serde = [ "dep:serde" ]
|
||||||
fmt = []
|
fmt = []
|
||||||
iter = []
|
iter = []
|
||||||
|
std = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", optional = true } # MIT or Apache 2.0
|
serde = { version = "1.0", optional = true } # MIT or Apache 2.0
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
coremem_cross = { path = ".", default-features = false, features = ["iter", "fmt"] }
|
coremem_cross = { path = ".", default-features = false, features = ["iter", "fmt", "std"] }
|
||||||
|
@@ -240,6 +240,33 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
mod into_vec {
|
||||||
|
use super::*;
|
||||||
|
pub struct IntoVecOp;
|
||||||
|
impl<Next> FoldOp<Vec<Next>, Next> for IntoVecOp {
|
||||||
|
type Output = Vec<Next>;
|
||||||
|
fn feed(&mut self, mut prev: Vec<Next>, next: Next) -> Self::Output {
|
||||||
|
prev.push(next);
|
||||||
|
prev
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub trait IntoVec<T> {
|
||||||
|
fn into_vec(self) -> Vec<T>;
|
||||||
|
}
|
||||||
|
impl<T, L> IntoVec<T> for L
|
||||||
|
where
|
||||||
|
L: Fold<IntoVecOp, Vec<T>, Output=Vec<T>>
|
||||||
|
{
|
||||||
|
fn into_vec(self) -> Vec<T> {
|
||||||
|
self.fold(IntoVecOp, Vec::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub use into_vec::{IntoVec, IntoVecOp};
|
||||||
|
|
||||||
pub trait MapVisitor<V> {
|
pub trait MapVisitor<V> {
|
||||||
type Output;
|
type Output;
|
||||||
fn map(&self, elem: V) -> Self::Output;
|
fn map(&self, elem: V) -> Self::Output;
|
||||||
@@ -502,6 +529,23 @@ mod test {
|
|||||||
assert_eq!(v.0, 24);
|
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::<u32>::into_vec(Empty::default()), vec![]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sum() {
|
fn sum() {
|
||||||
let list = (3i32, 4i32, 5i32).into_list();
|
let list = (3i32, 4i32, 5i32).into_list();
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#![no_std]
|
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
pub mod compound;
|
pub mod compound;
|
||||||
pub mod dim;
|
pub mod dim;
|
||||||
|
Reference in New Issue
Block a user