tshirtman, French
@tshirtman@mas.to avatar

So i was happy enough with for up to now, even as a beginner, but damn, not only i didn't really expect to be able to build code that stackoverflows, (did i misunderstood what rust promised me?), but debugging that is, as far as i can tell, a very bad experience, i got lucky once fixing my first mistake, but the current one is not obvious, so i'm installing lldb as i read it's one way to go about it, but not very on par with the rest of the (very good) experience so far.

pervognsen,
@pervognsen@mastodon.social avatar

@tshirtman Regarding the parenthetical question about "what Rust promised", you might be conflating buffer overflows and stack overflows. The latter is just an inevitable result of allowing general recursion with a bounded call stack. It's not a memory safety issue--it's similar in category to a well-defined abort/fatal error. Even though the quality of the error reporting for stack overflows is usually worse than for panics, it's still well-defined behavior.

jaxter184,

@pervognsen @tshirtman To add on to this, safe Rust also allows for memory leaks, which are a type of memory issue, but not a type of memory safety issue.

tshirtman,
@tshirtman@mas.to avatar

@pervognsen yep, indeed, i realized that after finding my issue 😅.

maciekglowka,

@tshirtman are you using Rc ?
That was the only way I could do SO (and it was on occasion of aoc as well:)

tshirtman,
@tshirtman@mas.to avatar

@maciekglowka involuntary recursion, i implemented PartialEq::eq as calling itself… 🤦‍♂️

mo8it,
@mo8it@fosstodon.org avatar

@tshirtman I never had a stack overflow in Rust so I can't really help :/
Did you use deep recursion?

tshirtman,
@tshirtman@mas.to avatar

@mo8it yeah, i finally understood my mistake 😆

impl PartialEq for HandTypes {
fn eq(&self, other: &Self) -> bool {
self == other
}
}

lldb did indicate me that the issue was in PartialEq, that was useful, but my eyes passed over it a few times before it clicked 🤦‍♂️

HandTypes is an Enum, so it felt a bit silly to implement.

tshirtman,
@tshirtman@mas.to avatar

@mo8it but i needed that to be able to implement Ord for the type, which i needed to sort my struct using that type.

I resorted to reuse a method i had built to convert each to a number of points, leveraging it to use the integer comparison.

impl PartialEq for HandTypes {
fn eq(&self, other: &Self) -> bool {
self.to_num() == other.to_num()
}
}

mo8it,
@mo8it@fosstodon.org avatar

@tshirtman What exactly is HandTypes? Is it just an enum with simple fields? There might be a much better way to do this.

tshirtman,
@tshirtman@mas.to avatar

@mo8it i pushed my solution, but it's a really simple enum without any field, just to represent the possible "pocker" hands of that puzzle.
https://codeberg.org/tshirtman/advent_of_code_2023/src/branch/main/src/day7.rs#L9

I'm sure there are better ways, i'm a complete rust newbe :)

I started from the doc example about how to implementing Ord, but it did feel weird i had to do all that.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • rust
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • cubers
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • JUstTest
  • everett
  • tacticalgear
  • modclub
  • anitta
  • cisconetworking
  • tester
  • ngwrru68w68
  • GTA5RPClips
  • normalnudes
  • megavids
  • Leos
  • provamag3
  • lostlight
  • All magazines