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

Fix compile of arbitrary feature. #505

Merged
merged 2 commits into from
Sep 8, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
include:
- version: stable
features: --features mint
- version: stable
features: --features bytemuck
- version: stable
features: --features arbitrary
- version: nightly
features: --features unstable
- version: nightly
Expand All @@ -40,9 +44,6 @@ jobs:
env:
RUST_BACKTRACE: 1

- name: bytemuck
run: cargo check --features bytemuck

build_result:
name: Result
runs-on: ubuntu-latest
Expand Down
18 changes: 17 additions & 1 deletion src/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use bytemuck::{Zeroable, Pod};
/// An angle in radians
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct Angle<T> {
pub radians: T,
}
Expand All @@ -34,6 +33,23 @@ unsafe impl<T: Zeroable> Zeroable for Angle<T> {}
#[cfg(feature = "bytemuck")]
unsafe impl<T: Pod> Pod for Angle<T> {}

#[cfg(feature = "arbitrary")]
impl<'a, T> arbitrary::Arbitrary<'a> for Angle<T>
where
T: arbitrary::Arbitrary<'a>,
{
// This implementation could be derived, but the derive would require an `extern crate std`.
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Angle {
radians: arbitrary::Arbitrary::arbitrary(u)?,
})
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
<T as arbitrary::Arbitrary>::size_hint(depth)
}
}

impl<T> Angle<T> {
#[inline]
pub fn radians(radians: T) -> Self {
Expand Down