Skip to content

Commit bb44333

Browse files
committed
feat: making the crate no_std and alloc compatible
1 parent dc22fde commit bb44333

File tree

22 files changed

+56
-49
lines changed

22 files changed

+56
-49
lines changed

Cargo.toml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
name = "arbitrary"
33
version = "1.4.2" # Make sure this matches the derive crate version (not including the patch version)
44
authors = [
5-
"The Rust-Fuzz Project Developers",
6-
"Nick Fitzgerald <[email protected]>",
7-
"Manish Goregaokar <[email protected]>",
8-
"Simonas Kazlauskas <[email protected]>",
9-
"Brian L. Troutwine <[email protected]>",
10-
"Corey Farwell <[email protected]>",
5+
"The Rust-Fuzz Project Developers",
6+
"Nick Fitzgerald <[email protected]>",
7+
"Manish Goregaokar <[email protected]>",
8+
"Simonas Kazlauskas <[email protected]>",
9+
"Brian L. Troutwine <[email protected]>",
10+
"Corey Farwell <[email protected]>",
1111
]
1212
categories = ["development-tools::testing"]
1313
edition = "2021"
@@ -24,7 +24,10 @@ derive_arbitrary = { version = "~1.4.0", path = "./derive", optional = true }
2424

2525
[features]
2626
# Turn this feature on to enable support for `#[derive(Arbitrary)]`.
27+
default = ["std"]
2728
derive = ["derive_arbitrary"]
29+
std = ["alloc"]
30+
alloc = []
2831

2932
[[example]]
3033
name = "derive_enum"

fuzz/fuzz_targets/int_in_range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![no_main]
22

33
use arbitrary::{unstructured::Int, Arbitrary, Result, Unstructured};
4+
use core::{fmt::Display, ops::RangeInclusive};
45
use libfuzzer_sys::fuzz_target;
5-
use std::{fmt::Display, ops::RangeInclusive};
66

77
fuzz_target!(|data: &[u8]| {
88
fuzz(data).expect("`int_in_range` should never return an error");

src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{error, fmt};
1+
use core::{error, fmt};
22

33
/// An enumeration of buffer creation errors
44
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -41,14 +41,14 @@ impl error::Error for Error {}
4141
/// A `Result` with the error type fixed as `arbitrary::Error`.
4242
///
4343
/// Either an `Ok(T)` or `Err(arbitrary::Error)`.
44-
pub type Result<T, E = Error> = std::result::Result<T, E>;
44+
pub type Result<T, E = Error> = core::result::Result<T, E>;
4545

4646
#[cfg(test)]
4747
mod tests {
4848
// Often people will import our custom `Result` type because 99.9% of
4949
// results in a file will be `arbitrary::Result` but then have that one last
5050
// 0.1% that want to have a custom error type. Don't make them prefix that
51-
// 0.1% as `std::result::Result`; instead, let `arbitrary::Result` have an
51+
// 0.1% as `core::result::Result`; instead, let `arbitrary::Result` have an
5252
// overridable error type.
5353
#[test]
5454
fn can_use_custom_error_types_with_result() -> super::Result<(), String> {

src/foreign/alloc/borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{size_hint, Arbitrary, Result, Unstructured},
3-
std::borrow::{Cow, ToOwned},
3+
alloc::borrow::{Cow, ToOwned},
44
};
55

66
impl<'a, A> Arbitrary<'a> for Cow<'a, A>

src/foreign/alloc/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{size_hint, Arbitrary, Result, Unstructured},
3-
std::boxed::Box,
3+
alloc::boxed::Box,
44
};
55

66
impl<'a, A> Arbitrary<'a> for Box<A>

src/foreign/alloc/collections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{Arbitrary, Result, Unstructured},
3-
std::collections::binary_heap::BinaryHeap,
3+
alloc::collections::binary_heap::BinaryHeap,
44
};
55

66
impl<'a, A> Arbitrary<'a> for BinaryHeap<A>

src/foreign/alloc/collections/btree_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{Arbitrary, Result, Unstructured},
3-
std::collections::btree_map::BTreeMap,
3+
alloc::collections::btree_map::BTreeMap,
44
};
55

66
impl<'a, K, V> Arbitrary<'a> for BTreeMap<K, V>

src/foreign/alloc/collections/btree_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{Arbitrary, Result, Unstructured},
3-
std::collections::btree_set::BTreeSet,
3+
alloc::collections::btree_set::BTreeSet,
44
};
55

66
impl<'a, A> Arbitrary<'a> for BTreeSet<A>

src/foreign/alloc/collections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{Arbitrary, Result, Unstructured},
3-
std::collections::linked_list::LinkedList,
3+
alloc::collections::linked_list::LinkedList,
44
};
55

66
impl<'a, A> Arbitrary<'a> for LinkedList<A>

src/foreign/alloc/collections/vec_deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{Arbitrary, Result, Unstructured},
3-
std::collections::vec_deque::VecDeque,
3+
alloc::collections::vec_deque::VecDeque,
44
};
55

66
impl<'a, A> Arbitrary<'a> for VecDeque<A>

0 commit comments

Comments
 (0)