Has my motd gone too far? It loads a random ANSI catgirl from a folder. I use arch btw, server runs minimized Ubuntu Server.

you are viewing a single comment's thread
view the rest of the comments
[–] 5 points 1 year ago* (last edited 1 year ago) (4 children)

I've been learning Rust by going through The Book... there's some wack-ass syntax in that language. I've mostly used C# and Python so most of it just looks weird... I can more or less understand what while let Some((_, top)) = iter.next() { ... } is doing, but .for_each(|((_, _, t), (_, _, b))| { ... } just looks like an abomination. And I mean the syntax in general, not this code in particular.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 7 points 1 year ago (2 children)

    but .for_each(|((_, , t), (, _, b))| { ... } just looks like an abomination

    It's not so different in python: for ((_, _, t), (_, _, b)) in zip(top, bottom):

    Or in C#: .ForEach(((_, _, t), (_, _, b)) => Console.Write(...));

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 1 year ago* (last edited 1 year ago)
    .for_each(|((_, _, t), (_, _, b))| { ... }
    

    This is actually fairly similar to what C# has.

    This is a closure syntax:

    | arguments | { calls }
    

    In C#, the closest is lambda expressions, declared like this:

    ( arguments ) => { calls }
    

    Parentheses are tuple deconstructors. In C# you have exactly the same thing. Imagine you have a method that returns a two element tuple. If you do this:

    var (one, two) = MethodThatReturnsATuple();
    

    You'll get your tuple broken down automatically and variables one and two declared for you.

    First of all, I'm using .zip() to pair the rows of the picture by two, that returns a tuple, so, I have to deconstruct that. That's what the outer parentheses are for. The pixel enumeration stuff I'm using returns a tuple (u32, u32, &Rgba<u8>) first two values are x and y of the pixel, the third one is a reference to a structure with color data. I deconstruct those and just discard the position of the pixel, you do that with an underscore, same as C#.

    I'm not that far into learning myself, but I'm not a textbook learner at all. Poking around opensource projects and wrestling with the compiler prooved to educate me a lot more.

  • source
  • parent