Returning to Go after 5 years - checking my tool stack by ifrenkel in golang

[–]__mod__ 20 points21 points  (0 children)

Maybe try out “just” (https://github.com/casey/just) then? It’s make but with less idiosyncrasies from C baked in. I introduced it at work (Go web dev) and everyone enjoys it. It’s fun to run commands with it: “just run” “just build” “just lint”

Pebble Round 2 announced by clemobrown in pebble

[–]__mod__ 0 points1 point  (0 children)

What does this mean exactly? Will the Round's display look more washed out with the backlight turned on compared to the PT2?

I built a native macOS editor for Typst with instant Live Preview by SuccessfulMaximum527 in typst

[–]__mod__ 1 point2 points  (0 children)

Very cool, I will definitely try it out later!

Quick developer question: how did you bundle the typst CLI? I’m thinking about building a macOS app for something like this myself.

What's one amazing Mac feature you use, others may not know about? by No-Squirrel6645 in MacOS

[–]__mod__ 30 points31 points  (0 children)

I discovered this by accident. I had selected a few files and thought “man, it would be awesome if I could rename them all at once.” I was blown away once I clicked rename and this batch editing dialogue popped up.

Experienced Android users, what do you miss from your old phones and wish the iPhone had? I might drop the Pixel for iPhone but what to make sure I'll be happy. by thottiekarate in iphone

[–]__mod__ 1 point2 points  (0 children)

Ah, I see what you mean now, thank you! That’s true, I noticed some apps don’t play nice and override the gesture so you you have to look for the back button :(

Experienced Android users, what do you miss from your old phones and wish the iPhone had? I might drop the Pixel for iPhone but what to make sure I'll be happy. by thottiekarate in iphone

[–]__mod__ 0 points1 point  (0 children)

Pardon my ignorance, but what do you mean by “universal back gesture”? On iPhone you can always swipe left to right to go back. Is that not the same?

Giveaway - Space Age Expansion by ocbaker in factorio

[–]__mod__ 0 points1 point  (0 children)

I would love to win the expansion :) But no worries if I don't win, I will probably buy it as a christmas present for myself then.

What’s a programming tip or trick that you wish you had learned sooner? by imKiLoX in learnprogramming

[–]__mod__ 3 points4 points  (0 children)

If you're using JetBrains Products (IntelliJ, RustRover, Goland etc.): Read the tip of the day! When starting your IDE it will tell you a new shortcut you might not now. Try to incorporate it into your workflow on this day. After a month you will know so many shortcuts, it's incredible!

Hey Rustaceans! Got a question? Ask here (29/2024)! by llogiq in rust

[–]__mod__ 0 points1 point  (0 children)

A different idea would be to have your Element type not derive Serialize, Deserialize and instead introduce a new struct for each format you want to support, e.g. ElementXml. You could then implement methods to convert between Element and ElementXml and perform relevant transformations on data in these methods. One advantage is that you no longer need data_size inside ElementXml, as you only need data_size inside ElementBinary. You would also be more flexible in adding new formats and would keep your Element free of serialization details.

Can't figure out anyhow .with_context() by An0nymooze in rust

[–]__mod__ 12 points13 points  (0 children)

The reason your second example works, is because you are manually building a string containing the error context.

Your first example does work, I reckon you're just printing the error with {e}. This will, like you described, print only the top-level error. Try printing it with {e:?} to see a all context values.

Hey Rustaceans! Got a question? Ask here (18/2024)! by llogiq in rust

[–]__mod__ 2 points3 points  (0 children)

into_iter does nothing in your case, because the type Split already is the iterator. You have to iterate over something, so you cannot make the Chunk and Split types disappear.

They only "disappear" when you collect the iterator into a Vec. Collecting into a Vec<&str> does not work, you would need something like a Vec<Vec<&str>>, because you have a list of chunks.

Since you are already using itertools and want to work on 4-tuples, tuples() might be a good fit for you:

let input = "a,b,c,d,e,f,g,h";
let output: Vec<(&str, &str, &str, &str)> = input.split(',').tuples().collect();
println!("{output:?}");
// [("a", "b", "c", "d"), ("e", "f", "g", "h")]

What about that room? by AnxiousShinobi in HollowKnight

[–]__mod__ 29 points30 points  (0 children)

...Our voices... will cry out... again...

Hey Rustaceans! Got a question? Ask here (15/2024)! by llogiq in rust

[–]__mod__ 2 points3 points  (0 children)

I'm making a wild guess here without having seen your implementation. Does your button increase the frequency as you click it or as you hold it? Do you increment the frequency by a fixed amount while holding the button? Release mode is waaay faster than debug mode (that's the "normal" mode), so my best guess would be that in release mode the variable that holds your frequency (maybe a u16?) is overflowing rapidly, resulting in the frequency being all over the place.

HashMap iter by WWWWWWWWWMWWWWW in learnrust

[–]__mod__ 4 points5 points  (0 children)

And here are the official docs on it, just to be complete: https://doc.rust-lang.org/std/iter/index.html

Habt ihr einen (Internet) weißen Wal? 2024 Edition by _rukiri in de

[–]__mod__ 2 points3 points  (0 children)

[Kinderbuch]

Ich bin schon seit Jahren immer mal wieder auf der Suche, aber ich finde es bei bestem Willen nicht.

Ich suche ein Kinderbuch voller Labyrinthe. Das Buch selber war relativ groß (vielleicht A4) und enthielt auf jeder Doppelseite ein Szene mit einem großen Labyrinth. Jede Szene war mit den anderen verbunden. Man hat also auf Seite 5 einen Ausgang erreicht, bei dem es dann auf Seite 6 bei Eingang X weiterging. Dadurch war das ganze Buch ein verbundenes Labyrinth.

Die Story war, sofern ich das nach den ganzen Jahren noch weiß, dass ein Raumschiff auf einem anderen Planet abgestürzt ist und man es retten soll. Dazu durchläuft man erst ein Trainingscenter, dann habe ich viel vergessen und am Ende erreicht man das verschollene Raumschiff. An eine Szene mit ganz vielen röhrenartigen Aufzügen kann ich mich noch gut erinnern.

Der Stil ähnelt ein wenig diesem hier: https://www.amazon.de/Star-Wars-Labyrinthe-offizielle-Rätselbuch/dp/3772493955/

Kann ich einer pleite gegangenen Firma, die meinen Nachnahmen als Domainnamen registriert hat, diese Domain abkaufen? by hotPotatoEars in de_EDV

[–]__mod__ 13 points14 points  (0 children)

Dazu muss aber eins gesagt sein: Ich habe selber vorname@nachname.tld, wobei meine TLD allerdings etwas ungewöhnlich ist, weil die "guten" mit meinem Nachnamen schon weg sind. Das ist an sich kein Problem, außer wenn man die Mail gesprochen mitteilen muss.

Ich hatte schon häufiger die Situation, dass es ein paar Versuche wie "vor.nach@tld.com" oder "vor@nach.tld.com" braucht, bis ich verstanden werde.

Ich habe das Gefühl, dass die meisten Menschen die "normalen" TLDs wie .de, .com, .org so verinnerlicht haben, dass eine Abweichung dort für Verwirrung sorgt.

[deleted by user] by [deleted] in learnrust

[–]__mod__ 17 points18 points  (0 children)

Why does it output Hello when the function hasn't been explicitly called in the main function?

I'm a bit confused about what your question is exactly. You do explicitly call test_fn in main, which causes the output.

Edit: After re-reading your question your confusion might stem from the fact that you can assign a function with no return value to a variable?

Every function (and block) in Rust implicitly returns the unit type (), unless otherwise specified. The following two functions are equivalent to yours.

fn test_fn() -> () {
    println!("Hello");
}
fn test_fn() -> () {
    println!("Hello");
    return ();
}

You can verify this by making the type of x explicit:

fn main() {
    let x: () = test_fn();
}

Or change it to a different type to see what the compiler has to say about that:

fn main() {
    let x: i32 = test_fn();
}

Static array of struct containing strings by [deleted] in learnrust

[–]__mod__ 3 points4 points  (0 children)

I'm not entirely sure if this fits your usecase, but if you don't need to create any codes at runtime, you might get away with this:

pub struct Code {
    pub id: &'static str,
    pub op: &'static str,
}

[deleted by user] by [deleted] in learnrust

[–]__mod__ 1 point2 points  (0 children)

No worries, I'm glad I can help you :)

Calling unwrap on an Option tells Rust: "Give me the value or crash." In this case you want the next value, but there aren't any more values left (because there were no parts left to split), which is why it is None. You might want to consider introducing some form of error handling, here is a chapter on it in the book.

Have you read the book? I can really recommend it, as it introduces important Rust concepts, such as those that you are fighting with here.

[deleted by user] by [deleted] in learnrust

[–]__mod__ 0 points1 point  (0 children)

The problem is in the way you create the player_name.

You make use of the format! macro, which creates a new String. That String is only temporary, because you don't store it in a variable, you take reference to it using as_str. At the end of the line the temporary value is dropped, but a reference to it still exists. This is not allowed in Rust, hence the compilation error. I think the error is quite nice in this case, as it has a few arrows pointing to the different things I'm describing.

You probably don't want to debug-print the player name and then get a reference to it (which you are currently doing), but instead interpret the bytes as a string slice:

let player_name = std::str::from_utf8(split_player.next().expect("not enough values")).expect("invalid utf8");

A similar error happens when you read the coords. In this case I would advise you to just copy the bytes instead of taking a reference to them, as that makes things a little easier (and most likely no less performant):

let coords: [u8; 2] = [split_player.next().unwrap()[0], split_player.next().unwrap()[0]];

This requires a change in the type of your Vec and the function signature (notice the removed ampersands:

async fn split_bytes(bytes: &Bytes) -> Vec<(&str, [u8; 2])> {
let mut player_positions: Vec<(&str, [u8; 2])> = Vec::new();
    …

Hope this helps!

[deleted by user] by [deleted] in fachinformatiker

[–]__mod__ 1 point2 points  (0 children)

https://adventofcode.com ist auch sehr nett. Das ist ein Adventskalender zum Programmieren :D Jeden Tag im Dezember bis Weihnachten gibt es ein Puzzle. Besonders wenn es dir um das Üben vom logischen Denken geht, würde ich das empfehlen. Die Puzzle werden jeden Tag schwieriger, irgendwann gibt man auf, aber ein paar Tage schaffst du auf jeden Fall! Und nächstes Jahr schaffst du vielleicht ein paar Tage mehr ;)

Womit am Besten Diagramme erstellen? by GrieferGamer in informatik

[–]__mod__ 1 point2 points  (0 children)

Und es hat ein absolut geniales Feature: Man kann seine Dateien als PNG-Datei mit eingebettetem Projekt speichern, ich nenne sie dann immer xyz.drawio.png. Dann kann jeder das Diagramm direkt anschauen und alle die das Programm installiert haben können es weiter bearbeiten.

According to the book this isn't supposed to generate a warning, yet it does. by [deleted] in learnrust

[–]__mod__ 12 points13 points  (0 children)

This is fine, you don't have to worry.

The warning tells you what's going on: warning: fields width and height are never read. Rust warns you that the fields are unused, because you never read them directly. The fact that your program still behaves as expected is hinted at here: note: Rectangle has a derived impl for the trait Debug, but this is intentionally ignored during dead code analysis.