Exactly. The functions of the super trait are also required when implementing the child trait’s functions, as you would expect from inheritance.
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.
Wow, that trait feature is great. I’ve been eagerly waiting for that one for a long time. Thank you to everyone who made that possible.
Sounds good. Please share what you find and what you end up going with.
There are a few different ways to solve this problem without using unsafe and I’m not sure what would be considered idiomatic. Another option is to ultimately encapsulate all of the nodes in a reference-counted box like Rc or Arc and specify the type of your parent/child/sibling references to the same reference-counted box type. With that, you just share cloned instances around as needed.
The primary drawback here is that for mutable access you end up having to perform a lock every time on an underlying Mutex (or something similar). You also no longer have direct access to the singular instance of the node.
There are pros and cons to every approach.
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.
deleted by creator
“Maintainable code and common patterns? But I prefer code-golfing my if-statements into one, long sequence of characters.” -coworker standing atop the Dunning-Kruger peak
I hate that it came to this, after so many Rust devs left, but all I can say is “Good.”
It happened to a friend who wasn’t passing in the proper types into their stored procedures, all strings, and “null” (not case sensitive) conflicted with actual null values. Everything in the web interface were strings, and so was null.
For some people it takes this mistake before they learn to always care about the data types you’re passing in.
I love the async closure update and the if-let scoping fix.
That’s an interesting take. I didn’t know that the tool screen
even existed, so I had no idea that it would be nice to have in my toolbelt for future needs. A README also helps those that may already know a lot about screen
and want to know the differences between screen
and their implementation.
There is nothing better in open source than a thorough, well-written README at the root of the project. Wanting others who don’t understand the source of the inspiration to be completely clueless is unfriendly (at best).
The README helped a lot, thanks. Just wanted to point out a minor typo, I think the second word under the “Client” section is meant to be the word “client”.
deleted by creator
Thanks for the explanation and README. I’ll check it out.
I don’t know anything about screen
. I think it would be great if you included a nice README.md
file in the root of your repo for explaining what screen is and what your repo does both differently and the same.
Please let me know if you do that. I’ll come and check out the repo at that point - kinda hard for me to want to jump directly into the code at the moment.
I’ve had mine on vibrate for years. Texting doesn’t trigger it, only calls. It’s been great. I look at my phone only when I’m ready to look at it.
I prefer to just throw the state into a database. Each table has their own “repository” type that knows how to save/load models and then I have “manager” types that use “repository” types to compose larger, feature-specific domain models.
I usually just use Sqlite for it’s simplicity but I’m not opposed to Postgres via Docker.
I’m surprised this doesn’t already exist.
This was a great blog post. I love Rust and Bevy, but I can definitely see why you made the switch.
The primary issue with your decision to use Rust/Bevy, for me, was that you were taking on the task of getting others to work in a difficult language for novice developers. I would never suggest Rust as someone’s first language, coupling that with a regularly-changing library like Bevy.
I would love to know what the pros and cons were between Unity and Godot. If you were going to switch to C# anyway, Godot seems like the next logic choice to me, so I’m curious about what your team’s evaluation was for that engine.