Skip to content

Commit 194a271

Browse files
committed
Use types from core where possible
1 parent 803f2df commit 194a271

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/error.rs

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

33
/// An enumeration of buffer creation errors
44
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -32,12 +32,12 @@ impl fmt::Display for Error {
3232
}
3333
}
3434

35-
impl error::Error for Error {}
35+
impl std::error::Error for Error {}
3636

3737
/// A `Result` with the error type fixed as `arbitrary::Error`.
3838
///
3939
/// Either an `Ok(T)` or `Err(arbitrary::Error)`.
40-
pub type Result<T, E = Error> = std::result::Result<T, E>;
40+
pub type Result<T, E = Error> = core::result::Result<T, E>;
4141

4242
#[cfg(test)]
4343
mod tests {

src/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZ
4343
use core::ops::{Range, RangeBounds, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive};
4444
use core::str;
4545
use core::time::Duration;
46+
use core::ops::Bound;
47+
use core::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize};
4648
use std::borrow::{Cow, ToOwned};
4749
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
4850
use std::ffi::{CString, OsString};
4951
use std::hash::BuildHasher;
5052
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
51-
use std::ops::Bound;
5253
use std::path::PathBuf;
5354
use std::rc::Rc;
54-
use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize};
5555
use std::sync::{Arc, Mutex};
5656

5757
/// Generate arbitrary structured values from raw, unstructured data.
@@ -381,7 +381,7 @@ impl_arbitrary_for_floats! {
381381

382382
impl<'a> Arbitrary<'a> for char {
383383
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
384-
use std::char;
384+
use core::char;
385385
// The highest unicode code point is 0x11_FFFF
386386
const CHAR_END: u32 = 0x11_0000;
387387
// The size of the surrogate blocks
@@ -560,7 +560,7 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Option<A> {
560560
}
561561
}
562562

563-
impl<'a, A: Arbitrary<'a>, B: Arbitrary<'a>> Arbitrary<'a> for std::result::Result<A, B> {
563+
impl<'a, A: Arbitrary<'a>, B: Arbitrary<'a>> Arbitrary<'a> for core::result::Result<A, B> {
564564
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
565565
Ok(if <bool as Arbitrary<'a>>::arbitrary(u)? {
566566
Ok(<A as Arbitrary>::arbitrary(u)?)
@@ -1116,9 +1116,9 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for iter::Empty<A> {
11161116
}
11171117
}
11181118

1119-
impl<'a, A: ?Sized> Arbitrary<'a> for ::std::marker::PhantomData<A> {
1119+
impl<'a, A: ?Sized> Arbitrary<'a> for core::marker::PhantomData<A> {
11201120
fn arbitrary(_: &mut Unstructured<'a>) -> Result<Self> {
1121-
Ok(::std::marker::PhantomData)
1121+
Ok(core::marker::PhantomData)
11221122
}
11231123

11241124
#[inline]
@@ -1127,9 +1127,9 @@ impl<'a, A: ?Sized> Arbitrary<'a> for ::std::marker::PhantomData<A> {
11271127
}
11281128
}
11291129

1130-
impl<'a> Arbitrary<'a> for ::std::marker::PhantomPinned {
1130+
impl<'a> Arbitrary<'a> for core::marker::PhantomPinned {
11311131
fn arbitrary(_: &mut Unstructured<'a>) -> Result<Self> {
1132-
Ok(::std::marker::PhantomPinned)
1132+
Ok(core::marker::PhantomPinned)
11331133
}
11341134

11351135
#[inline]
@@ -1138,9 +1138,9 @@ impl<'a> Arbitrary<'a> for ::std::marker::PhantomPinned {
11381138
}
11391139
}
11401140

1141-
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for ::std::num::Wrapping<A> {
1141+
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for core::num::Wrapping<A> {
11421142
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1143-
Arbitrary::arbitrary(u).map(::std::num::Wrapping)
1143+
Arbitrary::arbitrary(u).map(core::num::Wrapping)
11441144
}
11451145

11461146
#[inline]

src/size_hint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ pub fn and_all(hints: &[(usize, Option<usize>)]) -> (usize, Option<usize>) {
4242
/// `lhs` and `rhs` size hints.
4343
#[inline]
4444
pub fn or(lhs: (usize, Option<usize>), rhs: (usize, Option<usize>)) -> (usize, Option<usize>) {
45-
let lower = std::cmp::min(lhs.0, rhs.0);
45+
let lower = core::cmp::min(lhs.0, rhs.0);
4646
let upper = lhs
4747
.1
48-
.and_then(|lhs| rhs.1.map(|rhs| std::cmp::max(lhs, rhs)));
48+
.and_then(|lhs| rhs.1.map(|rhs| core::cmp::max(lhs, rhs)));
4949
(lower, upper)
5050
}
5151

src/unstructured.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
//! Wrappers around raw, unstructured bytes.
1010
1111
use crate::{Arbitrary, Error, Result};
12-
use std::marker::PhantomData;
13-
use std::ops::ControlFlow;
14-
use std::{mem, ops};
12+
use core::marker::PhantomData;
13+
use core::ops::ControlFlow;
14+
use core::{mem, ops};
1515

1616
/// A source of unstructured data.
1717
///
@@ -186,9 +186,9 @@ impl<'a> Unstructured<'a> {
186186
///
187187
/// ```
188188
/// use arbitrary::{Arbitrary, Result, Unstructured};
189-
/// # pub struct MyCollection<T> { _t: std::marker::PhantomData<T> }
189+
/// # pub struct MyCollection<T> { _t: core::marker::PhantomData<T> }
190190
/// # impl<T> MyCollection<T> {
191-
/// # pub fn with_capacity(capacity: usize) -> Self { MyCollection { _t: std::marker::PhantomData } }
191+
/// # pub fn with_capacity(capacity: usize) -> Self { MyCollection { _t: core::marker::PhantomData } }
192192
/// # pub fn insert(&mut self, element: T) {}
193193
/// # }
194194
///
@@ -218,7 +218,7 @@ impl<'a> Unstructured<'a> {
218218
let byte_size = self.arbitrary_byte_size()?;
219219
let (lower, upper) = <ElementType as Arbitrary>::size_hint(0);
220220
let elem_size = upper.unwrap_or(lower * 2);
221-
let elem_size = std::cmp::max(1, elem_size);
221+
let elem_size = core::cmp::max(1, elem_size);
222222
Ok(byte_size / elem_size)
223223
}
224224

@@ -238,19 +238,19 @@ impl<'a> Unstructured<'a> {
238238
// We only consume as many bytes as necessary to cover the entire
239239
// range of the byte string.
240240
// Note: We cast to u64 so we don't overflow when checking std::u32::MAX + 4 on 32-bit archs
241-
let len = if self.data.len() as u64 <= std::u8::MAX as u64 + 1 {
241+
let len = if self.data.len() as u64 <= core::u8::MAX as u64 + 1 {
242242
let bytes = 1;
243243
let max_size = self.data.len() - bytes;
244244
let (rest, for_size) = self.data.split_at(max_size);
245245
self.data = rest;
246246
Self::int_in_range_impl(0..=max_size as u8, for_size.iter().copied())?.0 as usize
247-
} else if self.data.len() as u64 <= std::u16::MAX as u64 + 2 {
247+
} else if self.data.len() as u64 <= core::u16::MAX as u64 + 2 {
248248
let bytes = 2;
249249
let max_size = self.data.len() - bytes;
250250
let (rest, for_size) = self.data.split_at(max_size);
251251
self.data = rest;
252252
Self::int_in_range_impl(0..=max_size as u16, for_size.iter().copied())?.0 as usize
253-
} else if self.data.len() as u64 <= std::u32::MAX as u64 + 4 {
253+
} else if self.data.len() as u64 <= core::u32::MAX as u64 + 4 {
254254
let bytes = 4;
255255
let max_size = self.data.len() - bytes;
256256
let (rest, for_size) = self.data.split_at(max_size);
@@ -520,7 +520,7 @@ impl<'a> Unstructured<'a> {
520520
/// assert_eq!(buf, [0, 0]);
521521
/// ```
522522
pub fn fill_buffer(&mut self, buffer: &mut [u8]) -> Result<()> {
523-
let n = std::cmp::min(buffer.len(), self.data.len());
523+
let n = core::cmp::min(buffer.len(), self.data.len());
524524
buffer[..n].copy_from_slice(&self.data[..n]);
525525
for byte in buffer[n..].iter_mut() {
526526
*byte = 0;
@@ -764,7 +764,7 @@ impl<'a, ElementType: Arbitrary<'a>> Iterator for ArbitraryTakeRestIter<'a, Elem
764764
/// Don't implement this trait yourself.
765765
pub trait Int:
766766
Copy
767-
+ std::fmt::Debug
767+
+ core::fmt::Debug
768768
+ PartialOrd
769769
+ Ord
770770
+ ops::Sub<Self, Output = Self>

0 commit comments

Comments
 (0)