Debian Codegraph @

src/value.rs

raw symbols SCIP
1 use Sourcerust-analyzer cargo random 0.12.2 source/Source#;
2
3 /// A random value.
4 pub trait Valuerust-analyzer cargo random 0.12.2 value/Value# {
5 /// Read a random value.
6 fn readrust-analyzer cargo random 0.12.2 value/Value#read().<S>(&mut S) -> Self where S: Sourcerust-analyzer cargo random 0.12.2 source/Source#;
7 }
8
9 macro_rules! implementrust-analyzer cargo random 0.12.2 value/implement!(
10 ($reader:ident as $($kind:ty),*) => {
11 $(impl Value for $kind {
12 #[inline(always)]
13 fn read<S>(source: &mut S) -> Self where S: Source {
14 source.$reader() as $kind
15 }
16 })*
17 }
18 );
19
20 implementrust-analyzer cargo random 0.12.2 value/implement!!(read_f64rust-analyzer cargo random 0.12.2 source/Source#read_f64(). as f32, f64);
21 implementrust-analyzer cargo random 0.12.2 value/implement!!(read_u64rust-analyzer cargo random 0.12.2 source/Source#read_u64(). as i8, i16, i32, i64, isize);
22 implementrust-analyzer cargo random 0.12.2 value/implement!!(read_u64rust-analyzer cargo random 0.12.2 source/Source#read_u64(). as u8, u16, u32, u64, usize);
23
24 #[cfg(test)]
25 mod testsrust-analyzer cargo random 0.12.2 value/tests/ {
26 use {Sourcerust-analyzer cargo random 0.12.2 source/Source#, Valuerust-analyzer cargo random 0.12.2 value/Value#, Xorshift128Plusrust-analyzer cargo random 0.12.2 xorshift/Xorshift128Plus#};
27
28 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
29 fn readrust-analyzer cargo random 0.12.2 value/tests/read().() {
30 let mut source = Xorshift128Plusrust-analyzer cargo random 0.12.2 xorshift/Xorshift128Plus#::newrust-analyzer cargo random 0.12.2 xorshift/impl#[Xorshift128Plus]new().([42, 69]);
31
32 macro_rules! readrust-analyzer cargo random 0.12.2 value/tests/read!(
33 ($($kind:ident => [$one:expr, $two:expr],)*) => ({$(
34 assert_eq!(source.read::<$kind>(), $one);
35 assert_eq!($kind::read(&mut source), $two);
36 )*});
37 );
38
39 readrust-analyzer cargo random 0.12.2 value/tests/read!! {
40 i8 => [52, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][Neg]neg().34],
41 i16 => [-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().17348, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1036],
42 i32 => [948125133, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1432682055],
43 i64 => [-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().6330235019914458621, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().4877218639256617945],
44 }
45 }
46 }