Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal use_alloc feature #474

Merged
merged 3 commits into from Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Expand Up @@ -2,22 +2,25 @@ language: rust
sudo: false
matrix:
include:
- rust: 1.32.0
- rust: 1.36.0
script:
- |
cargo build --verbose --no-default-features &&
cargo build --verbose --no-default-features --features "use_alloc" &&
cargo build --verbose --features "$FEATURES"
- rust: stable
script:
- |
cargo build --verbose --no-default-features &&
cargo build --verbose --no-default-features --features "use_alloc" &&
cargo build --verbose --features "$FEATURES" &&
cargo test --verbose --features "$FEATURES" &&
cargo bench --no-run --verbose --features "$FEATURES"
- rust: beta
script:
- |
cargo build --verbose --no-default-features &&
cargo build --verbose --no-default-features --features "use_alloc" &&
cargo build --verbose --features "$FEATURES" &&
cargo test --verbose --features "$FEATURES" &&
cargo bench --no-run --verbose --features "$FEATURES"
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -38,7 +38,8 @@ version = "0.2"

[features]
default = ["use_std"]
use_std = []
use_std = ["use_alloc"]
use_alloc = []

[profile]
bench = { debug = true }
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/mod.rs
Expand Up @@ -11,7 +11,7 @@ pub use self::coalesce::*;
pub use self::map::{map_into, map_ok, MapInto, MapOk};
#[allow(deprecated)]
pub use self::map::MapResults;
#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
pub use self::multi_product::*;

use std::fmt;
Expand Down
4 changes: 3 additions & 1 deletion src/adaptors/multi_product.rs
@@ -1,8 +1,10 @@
#![cfg(feature = "use_std")]
#![cfg(feature = "use_alloc")]

use crate::size_hint;
use crate::Itertools;

use alloc::vec::Vec;

#[derive(Clone)]
/// An iterator adaptor that iterates over the cartesian product of
/// multiple iterators of type `I`.
Expand Down
1 change: 1 addition & 0 deletions src/combinations.rs
@@ -1,6 +1,7 @@
use std::fmt;

use super::lazy_buffer::LazyBuffer;
use alloc::vec::Vec;

/// An iterator to iterate through all the `k`-length combinations in an iterator.
///
Expand Down
3 changes: 2 additions & 1 deletion src/combinations_with_replacement.rs
@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use std::fmt;

use super::lazy_buffer::LazyBuffer;
Expand Down Expand Up @@ -44,7 +45,7 @@ where
I: Iterator,
I::Item: Clone,
{
let indices: Vec<usize> = vec![0; k];
let indices: Vec<usize> = alloc::vec![0; k];
let pool: LazyBuffer<I> = LazyBuffer::new(iter);

CombinationsWithReplacement {
Expand Down
27 changes: 16 additions & 11 deletions src/free.rs
Expand Up @@ -3,31 +3,36 @@
//! The benefit of free functions is that they accept any `IntoIterator` as
//! argument, so the resulting code may be easier to read.

#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
use std::fmt::Display;
use std::iter::{self, Zip};
#[cfg(feature = "use_std")]
type VecIntoIter<T> = ::std::vec::IntoIter<T>;
#[cfg(feature = "use_alloc")]
type VecIntoIter<T> = alloc::vec::IntoIter<T>;

#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
use alloc::{
string::String,
};

#[cfg(feature = "use_alloc")]
use crate::Itertools;

pub use crate::adaptors::{
interleave,
merge,
put_back,
};
#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
pub use crate::put_back_n_impl::put_back_n;
#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
pub use crate::multipeek_impl::multipeek;
#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
pub use crate::peek_nth::peek_nth;
#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
pub use crate::kmerge_impl::kmerge;
pub use crate::zip_eq_impl::zip_eq;
pub use crate::merge_join::merge_join_by;
#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
pub use crate::rciter_impl::rciter;

/// Iterate `iterable` with a running index.
Expand Down Expand Up @@ -208,7 +213,7 @@ pub fn min<I>(iterable: I) -> Option<I::Item>
///
/// assert_eq!(join(&[1, 2, 3], ", "), "1, 2, 3");
/// ```
#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
pub fn join<I>(iterable: I, sep: &str) -> String
where I: IntoIterator,
I::Item: Display
Expand All @@ -228,7 +233,7 @@ pub fn join<I>(iterable: I, sep: &str) -> String
///
/// assert_equal(sorted("rust".chars()), "rstu".chars());
/// ```
#[cfg(feature = "use_std")]
#[cfg(feature = "use_alloc")]
pub fn sorted<I>(iterable: I) -> VecIntoIter<I::Item>
where I: IntoIterator,
I::Item: Ord
Expand Down
2 changes: 1 addition & 1 deletion src/groupbylazy.rs
@@ -1,5 +1,5 @@
use std::cell::{Cell, RefCell};
use std::vec;
use alloc::vec::{self, Vec};

/// A trait to unify FnMut for GroupBy with the chunk key in IntoChunks
trait KeyFunction<A> {
Expand Down
1 change: 1 addition & 0 deletions src/kmerge_impl.rs
@@ -1,6 +1,7 @@
use crate::size_hint;
use crate::Itertools;

use alloc::vec::Vec;
use std::mem::replace;
use std::fmt;

Expand Down
1 change: 1 addition & 0 deletions src/lazy_buffer.rs
@@ -1,4 +1,5 @@
use std::ops::Index;
use alloc::vec::Vec;

#[derive(Debug, Clone)]
pub struct LazyBuffer<I: Iterator> {
Expand Down