Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

23
vendor/num-derive/tests/empty_enum.rs vendored Normal file
View File

@@ -0,0 +1,23 @@
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate num as num_renamed;
#[macro_use]
extern crate num_derive;
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive)]
enum Color {}
#[test]
fn test_empty_enum() {
let v: [Option<Color>; 1] = [num_renamed::FromPrimitive::from_u64(0)];
assert_eq!(v, [None]);
}

11
vendor/num-derive/tests/issue-16.rs vendored Normal file
View File

@@ -0,0 +1,11 @@
macro_rules! get_an_isize {
() => {
0_isize
};
}
#[derive(num_derive::FromPrimitive)]
pub enum CLikeEnum {
VarA = get_an_isize!(),
VarB = 2,
}

17
vendor/num-derive/tests/issue-6.rs vendored Normal file
View File

@@ -0,0 +1,17 @@
#![deny(trivial_numeric_casts)]
#[macro_use]
extern crate num_derive;
#[derive(FromPrimitive, ToPrimitive)]
pub enum SomeEnum {
A = 1,
}
#[test]
fn test_trivial_numeric_casts() {
use num::{FromPrimitive, ToPrimitive};
assert!(SomeEnum::from_u64(1).is_some());
assert!(SomeEnum::from_i64(-1).is_none());
assert_eq!(SomeEnum::A.to_u64(), Some(1));
}

18
vendor/num-derive/tests/issue-9.rs vendored Normal file
View File

@@ -0,0 +1,18 @@
#![deny(unused_qualifications)]
#[macro_use]
extern crate num_derive;
use num::FromPrimitive;
use num::ToPrimitive;
#[derive(FromPrimitive, ToPrimitive)]
pub enum SomeEnum {
A = 1,
}
#[test]
fn test_unused_qualifications() {
assert!(SomeEnum::from_u64(1).is_some());
assert!(SomeEnum::from_i64(-1).is_none());
assert!(SomeEnum::A.to_i64().is_some());
}

View File

@@ -0,0 +1,2 @@
// Same source, just compiled for 2015 edition
include!("newtype.rs");

View File

@@ -0,0 +1,2 @@
// Same source, just compiled for 2018 edition
include!("newtype.rs");

108
vendor/num-derive/tests/newtype.rs vendored Normal file
View File

@@ -0,0 +1,108 @@
extern crate num as num_renamed;
#[macro_use]
extern crate num_derive;
use crate::num_renamed::{
Float, FromPrimitive, Num, NumCast, One, Signed, ToPrimitive, Unsigned, Zero,
};
use std::ops::Neg;
#[derive(PartialEq, Zero, One, NumOps, Num, Unsigned)]
struct MyNum(u32);
#[test]
fn test_derive_unsigned_works() {
fn do_nothing_on_unsigned(_input: impl Unsigned) {}
let x = MyNum(42);
do_nothing_on_unsigned(x);
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
PartialOrd,
ToPrimitive,
FromPrimitive,
NumOps,
NumCast,
One,
Zero,
Num,
Float,
Signed,
)]
struct MyFloat(f64);
impl Neg for MyFloat {
type Output = MyFloat;
fn neg(self) -> Self {
MyFloat(self.0.neg())
}
}
#[test]
fn test_from_primitive() {
assert_eq!(MyFloat::from_u32(25), Some(MyFloat(25.0)));
}
#[test]
fn test_from_primitive_128() {
assert_eq!(
MyFloat::from_i128(std::i128::MIN),
Some(MyFloat((-2.0).powi(127)))
);
}
#[test]
fn test_to_primitive() {
assert_eq!(MyFloat(25.0).to_u32(), Some(25));
}
#[test]
fn test_to_primitive_128() {
let f = MyFloat::from_f32(std::f32::MAX).unwrap();
assert_eq!(f.to_i128(), None);
assert_eq!(f.to_u128(), Some(0xffff_ff00_0000_0000_0000_0000_0000_0000));
}
#[test]
fn test_num_ops() {
assert_eq!(MyFloat(25.0) + MyFloat(10.0), MyFloat(35.0));
assert_eq!(MyFloat(25.0) - MyFloat(10.0), MyFloat(15.0));
assert_eq!(MyFloat(25.0) * MyFloat(2.0), MyFloat(50.0));
assert_eq!(MyFloat(25.0) / MyFloat(10.0), MyFloat(2.5));
assert_eq!(MyFloat(25.0) % MyFloat(10.0), MyFloat(5.0));
}
#[test]
fn test_num_cast() {
assert_eq!(<MyFloat as NumCast>::from(25u8), Some(MyFloat(25.0)));
}
#[test]
fn test_zero() {
assert_eq!(MyFloat::zero(), MyFloat(0.0));
}
#[test]
fn test_one() {
assert_eq!(MyFloat::one(), MyFloat(1.0));
}
#[test]
fn test_num() {
assert_eq!(MyFloat::from_str_radix("25", 10).ok(), Some(MyFloat(25.0)));
}
#[test]
fn test_float() {
assert_eq!(MyFloat(4.0).log(MyFloat(2.0)), MyFloat(2.0));
}
#[test]
fn test_signed() {
assert!(MyFloat(-2.0).is_negative())
}

View File

@@ -0,0 +1,13 @@
#![no_implicit_prelude]
use ::num_derive::*;
#[derive(FromPrimitive, ToPrimitive)]
enum Color {
Red,
Blue,
Green,
}
#[derive(FromPrimitive, ToPrimitive, NumCast, PartialEq, Zero, One, NumOps, Num)]
struct NewI32(i32);

View File

@@ -0,0 +1,20 @@
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[macro_use]
extern crate num_derive;
#[derive(Debug, FromPrimitive, ToPrimitive)]
enum Direction {
Up,
Down,
Left,
Right,
}

View File

@@ -0,0 +1,2 @@
// Same source, just compiled for 2015 edition
include!("trivial.rs");

View File

@@ -0,0 +1,2 @@
// Same source, just compiled for 2018 edition
include!("trivial.rs");

64
vendor/num-derive/tests/trivial.rs vendored Normal file
View File

@@ -0,0 +1,64 @@
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate num as num_renamed;
#[macro_use]
extern crate num_derive;
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive)]
enum Color {
Red,
Blue,
Green,
}
#[test]
fn test_from_primitive_for_trivial_case() {
let v: [Option<Color>; 4] = [
num_renamed::FromPrimitive::from_u64(0),
num_renamed::FromPrimitive::from_u64(1),
num_renamed::FromPrimitive::from_u64(2),
num_renamed::FromPrimitive::from_u64(3),
];
assert_eq!(
v,
[
Some(Color::Red),
Some(Color::Blue),
Some(Color::Green),
None
]
);
}
#[test]
fn test_to_primitive_for_trivial_case() {
let v: [Option<u64>; 3] = [
num_renamed::ToPrimitive::to_u64(&Color::Red),
num_renamed::ToPrimitive::to_u64(&Color::Blue),
num_renamed::ToPrimitive::to_u64(&Color::Green),
];
assert_eq!(v, [Some(0), Some(1), Some(2)]);
}
#[test]
fn test_reflexive_for_trivial_case() {
let before: [u64; 3] = [0, 1, 2];
let after: Vec<Option<u64>> = before
.iter()
.map(|&x| -> Option<Color> { num_renamed::FromPrimitive::from_u64(x) })
.map(|x| x.and_then(|x| num_renamed::ToPrimitive::to_u64(&x)))
.collect();
let before = before.iter().cloned().map(Some).collect::<Vec<_>>();
assert_eq!(before, after);
}

View File

@@ -0,0 +1,68 @@
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate num as num_renamed;
#[macro_use]
extern crate num_derive;
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive)]
enum Color {
Red,
Blue = 5,
Green,
Alpha = (-3 - (-5isize)) - 10,
}
#[test]
fn test_from_primitive_for_enum_with_custom_value() {
let v: [Option<Color>; 5] = [
num_renamed::FromPrimitive::from_u64(0),
num_renamed::FromPrimitive::from_u64(5),
num_renamed::FromPrimitive::from_u64(6),
num_renamed::FromPrimitive::from_u64(-8isize as u64),
num_renamed::FromPrimitive::from_u64(3),
];
assert_eq!(
v,
[
Some(Color::Red),
Some(Color::Blue),
Some(Color::Green),
Some(Color::Alpha),
None
]
);
}
#[test]
fn test_to_primitive_for_enum_with_custom_value() {
let v: [Option<u64>; 4] = [
num_renamed::ToPrimitive::to_u64(&Color::Red),
num_renamed::ToPrimitive::to_u64(&Color::Blue),
num_renamed::ToPrimitive::to_u64(&Color::Green),
num_renamed::ToPrimitive::to_u64(&Color::Alpha),
];
assert_eq!(v, [Some(0), Some(5), Some(6), Some(-8isize as u64)]);
}
#[test]
fn test_reflexive_for_enum_with_custom_value() {
let before: [u64; 3] = [0, 5, 6];
let after: Vec<Option<u64>> = before
.iter()
.map(|&x| -> Option<Color> { num_renamed::FromPrimitive::from_u64(x) })
.map(|x| x.and_then(|x| num_renamed::ToPrimitive::to_u64(&x)))
.collect();
let before = before.iter().cloned().map(Some).collect::<Vec<_>>();
assert_eq!(before, after);
}