()
| 88 | struct I64Source { |
| 89 | next: i64, |
| 90 | } |
| 91 | |
| 92 | impl DynSource for I64Source { |
| 93 | type Item = i64; |
| 94 | |
| 95 | fn next_value(&mut self) -> Option<Self::Item> { |
| 96 | let value = self.next; |
| 97 | self.next += 2; |
| 98 | Some(value) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | fn next_i32(source: &mut dyn DynSource<Item = i32>) -> i32 { |
| 103 | source.next_value().unwrap() |
| 104 | } |
| 105 | |
| 106 | fn next_i64(source: &mut dyn DynSource<Item = i64>) -> i64 { |
| 107 | source.next_value().unwrap() |
| 108 | } |
| 109 | |
| 110 | impl PrimitiveTraitObject for i32 { |
| 111 | fn doubled(&self) -> i32 { |
| 112 | *self * 2 |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | impl<T: PrimitiveTraitObject + ?Sized> PrimitiveTraitObject for &T { |
| 117 | fn doubled(&self) -> i32 { |
| 118 | (**self).doubled() |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | fn use_primitive_trait_object(value: &dyn PrimitiveTraitObject) -> i32 { |
| 123 | value.doubled() |
| 124 | } |
| 125 | |
| 126 | fn drop_send_from_any(value: &(dyn core::any::Any + Send)) -> &dyn core::any::Any { |
| 127 | value |
| 128 | } |
| 129 | |
| 130 | // --- First Implementation --- |
| 131 | struct SimpleAdder { |
| 132 | current_total: i32, |
| 133 | } |
| 134 | |
| 135 | impl Calculator for SimpleAdder { |
| 136 | fn calculate(&self, a: i32, b: i32) -> i32 { |
| 137 | a + b // Simple addition |
| 138 | } |
| 139 | |
| 140 | fn accumulate(&mut self, value: i32) { |
| 141 | self.current_total += value; |
| 142 | } |
| 143 | |
| 144 | fn get_value(&self) -> i32 { |
| 145 | self.current_total |
| 146 | } |
| 147 |
nothing calls this directly
no test coverage detected