This is a well trodden problem: It even has an implementation as a crate https://crates.io/crates/cascade
Previous motivations:
Previous discussions: