Skip to content
0
  • Home
  • Piero Bosio
  • Blog
  • World
  • Fediverso
  • News
  • Categories
  • Old Web Site
  • Recent
  • Popular
  • Tags
  • Users
  • Home
  • Piero Bosio
  • Blog
  • World
  • Fediverso
  • News
  • Categories
  • Old Web Site
  • Recent
  • Popular
  • Tags
  • Users
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Piero Bosio Social Web Site Personale Logo Fediverso

Social Forum federato con il resto del mondo. Non contano le istanze, contano le persone
jonathan@fedi.xirion.netundefined

jana

@jonathan@fedi.xirion.net
About
Posts
1
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

View Original

Posts

Recent Best Controversial

  • #AdventOfCode #Day3
    jonathan@fedi.xirion.netundefined jonathan@fedi.xirion.net

    @riffraff the type isn't so bad, though if it gets larger you could consider a type alias.

    max_bank could probably take a &[u64] letting you get rid of some of the vecs that are indeed not necessary. That also gets you the pass by reference you mentioned. For integers you never need to pass by reference since they're Copy. But it looks like you already knew that :) A vec is only necessary the first time when you deal with input since that's pretty dynamic. Then in the rest of your code you're just reading from that one vec, not necessarily growing it so a slice &[T] is enough. Note that a slice isn't quite the same as an array. A slice borrows some number of elements from a container like an array or vec. An array ([T; N]) is different in that its size is fixed at compile time. An array of 4 elements is pretty much equivalent to 4 values in different local variables, of the same type passed together in a single variable.

    If you like named arguments, sometimes passing a struct can be nice. Note that you can destructure structs in argument position, so struct Args{...} fn foo (Args {a,b,c}: Args){...} Though here I'm not sure I'd go for that.

    Rewriting a loop to iterators can sometimes be slightly faster, but I'd say what you do here is pretty good. Clippy is not always correct! It's trying to teach you something but in the end it's just a bunch of heuristics, it's not always right!

    Uncategorized adventofcode day3 rust
  • 1 / 1
  • Login

  • Login or register to search.
  • First post
    Last post