Actually I do not know how is this called but i know how a solution should looks like. Let say I have the following example:
let x = Some("xx");
let a = x.unwrap().to_string();
So here I applied two manipulations on x . First I unwrapped it and then converted it. If I were to create my own two methods that operate on x let say the first one (given x is an int) adds 50 to it and the second multiplies it by 10. and let say I wanna have the same interface as the one above, how would I go about it.
let x= 2;
x.add(50).mul(10); // and now my x = 520
any pointers ? Where to start ? how to create such methods ?
Side note: In this particular case, the std::ops module already defines traits with add and mul methods, so you can just import these existing traits instead of defining new ones (playground):
use std::ops::{Add, Mul};
println!("{}", 2i32.add(50).mul(10));