-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from asmello/wip
Slice-like Pointers
- Loading branch information
Showing
10 changed files
with
963 additions
and
1,059 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::{PointerBuf, Token}; | ||
use alloc::{ | ||
boxed::Box, | ||
string::{String, ToString}, | ||
vec::Vec, | ||
}; | ||
use quickcheck::Arbitrary; | ||
|
||
impl Arbitrary for Token { | ||
fn arbitrary(g: &mut quickcheck::Gen) -> Self { | ||
Self::new(String::arbitrary(g)) | ||
} | ||
|
||
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> { | ||
Box::new(ToString::to_string(self).shrink().map(Self::new)) | ||
} | ||
} | ||
|
||
impl Arbitrary for PointerBuf { | ||
fn arbitrary(g: &mut quickcheck::Gen) -> Self { | ||
let size = usize::arbitrary(g) % g.size(); | ||
Self::from_tokens((0..size).map(|_| Token::arbitrary(g)).collect::<Vec<_>>()) | ||
} | ||
|
||
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> { | ||
let tokens: Vec<_> = self.tokens().collect(); | ||
Box::new((0..self.count()).map(move |i| { | ||
let subset: Vec<_> = tokens | ||
.iter() | ||
.enumerate() | ||
.filter_map(|(j, t)| (i != j).then_some(t.clone())) | ||
.collect(); | ||
Self::from_tokens(subset) | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ pub mod prelude; | |
|
||
mod tokens; | ||
pub use tokens::*; | ||
|
||
#[cfg(test)] | ||
mod arbitrary; |
Oops, something went wrong.