Exactly. The functions of the super trait are also required when implementing the child trait's functions, as you would expect from inheritance.
Basically, you can generalize your trait types into their parent (super) traits for situations when functionality is specific to those supertrait objects.
As an example, if you have a trait CanBark and it is a super trait for the trait IsDog, you can coerce your references of &dyn IsDog into a &dyn CanBark. You can then work with other trait types that share a super trait.
trait CanBark {
fn bark(&self);
}
trait IsSeal: CanBark { }
trait IsDog: CanBark { }
fn bark_as_group(barkers: &Vec<&dyn CanBark>) {
for barker in barkers {
barker.bark();
}
}
let spot: &dyn IsDog = get_spot();
let seal: &dyn IsSeal = get_seal();
let barkers: Vec<&dyn CanBark> = Vec::new();
barkers.push(spot); // coerced
barkers.push(seal); // coerced
bark_as_group(&barkers);
At least, I hope this is possible now. If it's purely "you can return a coerced type from a function", that is less useful.
I had a coworker who would sometimes not create a method as being static to the class and would therefore need to create a default instance to call said method. "It's domain-driven design."
One way of solving this is to structure all of your nodes into a HashMap with the node ID as the key and the node type as the value. The underlying node type could have node IDs for referencing purposes. You lose the ability to reference the parent/child/sibling directly, but you avoid direct circular dependencies. That said, now you need to manage dangling references for when the node is removed from the main HashMap collection.
For those looking for more of the same great fun, please do yourself a favor and check out RiffTrax (link below). Done by the same guy.
Oh, okay. Thank you for clarifying. So doesn't that mean we should never have a compiler written in the same language that it compiles? Why would we ever choose to make the mistake of using the same language? Is it ever not a mistake?
It just felt so cliche, that the crazy discovery they make is that the strange stuff is alive. The writers couldn't make it sentient because then they'd need to explain why it's just like the Great Lake but different from the Great Lake. It just exists and Star Fleet happens to be the only ones who know about it.
Who wanted a visual reboot of the Klingons?
Discovery had so many problems for me: ship flies on magic mushrooms, her mom basically doesn't care about her anymore by the end of it - the show-starting plot line, and the Klingons look like sweaty orcs.
Who is writing SQL in the terminal?
Oh, yeah, vim motions are wonderful. I started using them when I installed Linux on my Chromebook due to the lack of a good keyboard setup (I still don't know where the Delete key is on that thing).
Yesterday doing a search using vim for a class that shared a lot of characters at the front with many other classes: /Bas.*Some I could have done a more precise search with better regex, but this was quick, easy, and worked.
livingcoder
0 post score0 comment score
You wouldn't know it with all of the crying they do any time a left-leaning policy position is shared online. You would think that they're being bullied off of the internet.