1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// src/traits/as_u64.rs : `AsU64`
/// Trait defining instance method `as_u64() : u64` that provides a
/// cost-free conversion into `u64`.
///
/// It is expected that the implementing type "is-a" `u64` in a direct
/// manner as well as in a logical manner.
///
/// # Additional Implementations on Foreign Types
///
/// ## Built-in Types
///
/// If the feature `"implement-AsU64-for-built_ins"`
/// is defined (as it is by `"default"`), then this is also implemented
/// for the following type(s):
/// - [`u64`];
pub trait AsU64 {
fn as_u64(&self) -> u64;
}
#[cfg(feature = "implement-AsU64-for-built_ins")]
mod impl_for_built_ins {
#![allow(non_snake_case)]
impl super::AsU64 for u64 {
#[inline]
fn as_u64(&self) -> u64 {
*self
}
}
}
#[cfg(test)]
mod tests {
#![allow(non_snake_case)]
use super::AsU64;
#[cfg(feature = "implement-AsU64-for-built_ins")]
#[test]
fn TEST_u64_AsU64() {
{
let v : u64 = 12345678;
let actual = v.as_u64();
assert_eq!(12345678, actual);
}
{
let v : &u64 = &12345678;
let actual = v.as_u64();
assert_eq!(12345678, actual);
}
}
}
// ///////////////////////////// end of file //////////////////////////// //