use batch_impl::batch_impl;
#[batch_impl(()^2 where{@0: Clone, @1: Copy} { fn tmk() -> u32 { 2 } })]
trait TupleWhereAt {
fn tmk() -> u32;
}
#[batch_impl(<T> AtWhere<T> Vec<T> where{T: Default} { fn an(&self) -> usize { self.len() } })]
trait AtWhere<T: Clone> {
fn an(&self) -> usize;
}
trait JoinMarker {}
impl JoinMarker for u8 {}
#[batch_impl(()^3-()^3 where{@0: JoinMarker, @5: Copy})]
trait JoinAtNum {}
#[test]
fn at_refs_numbered_match_in_join() {
fn assert_impl<T: JoinAtNum>() {}
assert_impl::<(u8, u16, u32, (u64, u128, usize))>();
}
#[batch_impl(()^2-()^2 where{@all_fresh: Clone})]
trait AllFreshWhere {}
#[batch_impl(()^2-()^2 where{@0..=1: Copy})]
trait RangeWhere {}
#[test]
fn at_all_fresh_and_range() {
fn assert_impl_all<T: AllFreshWhere>() {}
assert_impl_all::<(u8, u16, (u32, u64))>();
fn assert_impl_range<T: RangeWhere>() {}
assert_impl_range::<(u8, u16, (String, Vec<u8>))>();
}
#[batch_impl(()^3-()^3 where{@all_fresh: Clone, @0..=2: Copy})]
trait CombinedBatchWhere {}
#[test]
fn at_all_fresh_with_range_same_group() {
fn assert_impl<T: CombinedBatchWhere>() {}
assert_impl::<(u8, u16, u32, (u64, u128, usize))>();
}
#[batch_impl(()^1..=3 where{@0: Clone} { fn tmk() -> u32 { 2 } })]
trait RangeAtNum {
fn tmk() -> u32;
}
#[batch_impl(()^2, ()^3 where{@0: Clone})]
trait MultiAtNum {}
#[test]
fn at_refs_across_generation_units() {
assert_eq!(<(u8,) as RangeAtNum>::tmk(), 2);
assert_eq!(<(u8, u16) as RangeAtNum>::tmk(), 2);
assert_eq!(<(u8, u16, u32) as RangeAtNum>::tmk(), 2);
fn assert_impl<T: MultiAtNum>() {}
assert_impl::<(u8, u16)>();
assert_impl::<(u8, u16, u32)>();
}
#[batch_impl(()^3-()^3 where{@0_0: JoinMarker, @1_0: Copy})]
trait JoinAtGroup {}
#[test]
fn at_group_position_refs() {
fn assert_impl<T: JoinAtGroup>() {}
assert_impl::<(u8, u16, u32, (u64, u128, usize))>();
}
#[test]
fn where_position_refs() {
assert_eq!(<(u32, u32) as TupleWhereAt>::tmk(), 2);
let v = vec![1u32];
assert_eq!(v.an(), 1);
}
#[batch_impl((()^2)^Box<@0> where{@1: Clone})]
trait AtNumInType {}
#[batch_impl((()^2)^Box<@0_1>)]
trait AtGroupInType {}
#[test]
fn at_refs_in_target_type() {
fn check_num<T: AtNumInType>() {}
check_num::<(u8, u16, Box<u8>)>();
fn check_group<T: AtGroupInType>() {}
check_group::<(u8, u16, Box<u16>)>();
}