Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::Add;
- struct MyStruct(i32);
- struct MyStructString(String);
- impl Add for MyStruct {
- type Output = MyStruct;
- fn add(self, other: MyStruct) -> MyStruct {
- MyStruct(self.0 + other.0)
- }
- }
- impl Add for MyStructString {
- type Output = MyStructString;
- fn add(self, other: MyStructString) -> MyStructString {
- MyStructString(format!("{}{}", self.0, other.0))
- }
- }
- fn main() {
- let a = MyStruct(1);
- let b = MyStruct(2);
- let _c = a + b;
- let aa = MyStructString(String::from("A"));
- let bb = MyStructString(String::from("B"));
- let _cc = aa + bb;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement