How to organize chain processing in Rust?
⚓ Rust 📅 2025-12-10 👤 surdeus 👁️ 8I created a trait like:
pub trait Colorized : std::fmt::Display {
fn green(&self) -> ??? {
}
fn bright(&self) -> ??? {
}
....
So, I want to organize a chain of calls to the trait, for example:
println!("Colorized {}", message.green().bright());
Certainly I can implement the trait for str, but if I return str, then I will lose color attributes I set before. So an idea is to return ColorAttributeHolder. More likely, I will need to implement Colorized for it too, to be able to chain my calls. However I have few questions:
- where and how store the original caller of
Colorized? - how to pass
Colorizedto the next chained calls? The best is by a reference, but the firstselfand the nextselfcan be different and again I will lose valuable information.
Probably, my approach is wrong, so please share your approach.
3 posts - 3 participants
🏷️ Rust_feed