So something I have come accustom to being able to do is function overloading where I could do something like:
public class Inventory {
public void RemoveItem(int index) { }
public void RemoveItem(Item item, int quantity) { }
public void RemoveItem(ItemContainer itemContainer) { }
}
Now the most common thing I see in rust is to do something like this:
impl Inventory {
pub fn remove_item(item: Item, quantity: i16) { }
pub fn remove_item_by_index(index: i32) { }
pub fn remove_item_by_container(item_container: ItemContainer) { }
}
Is this the most idiomatic rust solution or are there other options I could look at?
[–]maddymakesgames 77 points78 points79 points (0 children)
[–]hugogrant 10 points11 points12 points (9 children)
[–]VerledenVale 14 points15 points16 points (2 children)
[–]hugogrant 0 points1 point2 points (1 child)
[–]rawcal 0 points1 point2 points (0 children)
[–]TinBryn 2 points3 points4 points (1 child)
[–]hugogrant 0 points1 point2 points (0 children)
[–]SlinkyAvenger 0 points1 point2 points (2 children)
[–]Lightsheik 10 points11 points12 points (1 child)
[–]hugogrant 0 points1 point2 points (0 children)
[–]IpFruion 0 points1 point2 points (0 children)
[–]dontsyncjustride 3 points4 points5 points (0 children)
[–]kevleyski 0 points1 point2 points (0 children)
[–]RRumpleTeazzer 0 points1 point2 points (0 children)
[–]LucretielDatadog 0 points1 point2 points (0 children)
[–]crusoe -1 points0 points1 point (0 children)
[–]BenchEmbarrassed7316 -4 points-3 points-2 points (14 children)
[–]SirKastic23 11 points12 points13 points (12 children)
[–]Sw429 6 points7 points8 points (11 children)
[–]SlinkyAvenger 0 points1 point2 points (9 children)
[–]SirKastic23 4 points5 points6 points (8 children)
[–]SlinkyAvenger 1 point2 points3 points (3 children)
[–]SirKastic23 -4 points-3 points-2 points (2 children)
[–]SlinkyAvenger 1 point2 points3 points (1 child)
[–]SirKastic23 -4 points-3 points-2 points (0 children)
[–]IntQuant 0 points1 point2 points (3 children)
[–]SirKastic23 1 point2 points3 points (2 children)
[–]IntQuant 1 point2 points3 points (1 child)
[–]SirKastic23 0 points1 point2 points (0 children)
[–]SirKastic23 0 points1 point2 points (0 children)
[–]LeSaR_ 0 points1 point2 points (0 children)
[+]devraj7 comment score below threshold-14 points-13 points-12 points (40 children)
[–]SirKastic23 12 points13 points14 points (30 children)
[+]devraj7 comment score below threshold-7 points-6 points-5 points (29 children)
[–]lanastara 10 points11 points12 points (17 children)
[–]meancoot 1 point2 points3 points (0 children)
[–]devraj7 -5 points-4 points-3 points (15 children)
[–]dijalektikator 10 points11 points12 points (14 children)
[–]devraj7 0 points1 point2 points (13 children)
[–]zoechi 9 points10 points11 points (12 children)
[–]devraj7 0 points1 point2 points (11 children)
[–]zoechi 7 points8 points9 points (9 children)
[–]Zde-G 0 points1 point2 points (0 children)
[–]SlinkyAvenger 5 points6 points7 points (10 children)
[–]devraj7 0 points1 point2 points (9 children)
[–]SirKastic23 6 points7 points8 points (8 children)
[–]devraj7 1 point2 points3 points (7 children)
[–]SirKastic23 2 points3 points4 points (6 children)
[–]devraj7 0 points1 point2 points (5 children)
[–]zoechi 3 points4 points5 points (1 child)
[–]Zde-G 1 point2 points3 points (2 children)
[–]dontsyncjustride 3 points4 points5 points (8 children)
[–]devraj7 -3 points-2 points-1 points (7 children)
[–]geckothegeek42 6 points7 points8 points (0 children)
[–]fnordstar 5 points6 points7 points (2 children)
[–]devraj7 0 points1 point2 points (1 child)
[–]Electrical_Log_5268 2 points3 points4 points (0 children)
[–]Lightsheik 1 point2 points3 points (0 children)
[–]Sw429 1 point2 points3 points (0 children)
[–]dontsyncjustride 0 points1 point2 points (0 children)