| 43 | } |
| 44 | |
| 45 | trait StaticConvert<T> { |
| 46 | fn convert(value: T) -> Self; |
| 47 | } |
| 48 | |
| 49 | impl StaticConvert<i32> for i64 { |
| 50 | fn convert(value: i32) -> Self { |
| 51 | value as i64 + 1 |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | impl StaticConvert<i32> for bool { |
| 56 | fn convert(value: i32) -> Self { |
| 57 | value != 0 |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | fn add_const<const N: i32>(value: i32) -> i32 { |
| 62 | value + N |
| 63 | } |
| 64 | |
| 65 | fn main() { |
| 66 | let a = identity(42); |
| 67 | let b = identity("hello"); |
| 68 | |
| 69 | assert!(a == 42); |
| 70 | assert!(b.len() == 5); |
| 71 | |
| 72 | let swapped = swap(1, "two"); |
| 73 | assert!(swapped.0 == "two"); |