1
8
submitted 23 hours ago* (last edited 23 hours ago) by thingsiplay@beehaw.org to c/programming@programming.dev

Hello folks. So I'm still not good at Rust and learn even basics after years (just on and off doing some stuff). I'm currently working on my first small GUI application with FLTK in Rust. It's not that important for my question, but I think this gives a bit of context. The actual question is about struct and impl, using a builder pattern like pattern, but without impl builder and build() function.

Normally with the builder pattern, there are at least two structs and impl blocks. One dedicated to build the first struct. But I am doing it with only one struct and impl block, without a build() function. But it is functionally (at least conceptional) the same, isn't it? A shorted example for illustration:

Edit: Man beehaw is ruining my code blocks removing the opening character for >, which wil be translated to < or or completely removed. I use a % to represent the opening.

struct AppSettings {
    input_directory: Option%PathBuf>,
    max_depth: u8,
}

impl AppSettings {
    fn new() -> Self {
        Self {
            input_directory: None,
            max_depth: 1,
        }
    }

    fn input_directory(mut self, path: String) -> Self {
        self.input_directory = match path.fullpath() {
            Ok(p) => Some(p),
            Err(_) => None,
        };

        self
    }

    fn max_depth(mut self, levels: u8) -> Self {
        self.max_depth = levels;

        self
    }
}

And this is then used in main like

    let mut appsettings = AppSettings::new()
        .input_directory("~/test".to_string())
        .max_depth(3);

BTW I have extended PathBuf and String with a few traits. So if you wonder why I have code like this path.fullpath() . So just ignore that part. I'm just asking about the builder pattern stuff. This works for me. Do I miss something? Why would I go and do the extra step of creating another struct and impl block to build it and a final struct, that is basically the same? I don't get that.

Is this approach okay in your mind?

2
56
3
35
4
24
2024 Stack Overflow Developer Survey (survey.stackoverflow.co)
5
16
6
27
7
7

In this article, we will explore the key differences between Ktor and Spring Boot for Kotlin developers based on the experience of various developers.

8
12

Massive context window, free tier, suuuuuuuper fast. So far the best copilot I've tested; highly recommended.

9
88

Not my blog, but the author's experience reminded me of my own frustrations with Microsoft GitHub.

10
8

This article aims to explore several common misconceptions of SwiftUI to help developers better understand and utilize SwiftUI

11
30

YAML and TOML suck. Long live the FAMF!

12
33

This part of this blog post has always made me happy and I come back it from time to time. This is regarding the scene in Tron Legacy when one of the characters stops another from hacking. If you'd like to see the scene for context here it is. The time code is when the particular portion is. https://youtu.be/Qeh3E67brBs&t=231

In addition to visual effects, I was asked to record myself using a unix terminal doing technologically feasible things. I took extra care in babysitting the elements through to final composite to ensure that the content would not be artistically altered beyond that feasibility. I take representing digital culture in film very seriously in lieu of having grown up in a world of very badly researched user interface greeble. I cringed during the part in Hackers (1995) when a screen saver with extruded "equations" is used to signify that the hacker has reached some sort of neural flow or ambiguous destination. I cringed for Swordfish and Jurassic Park as well. I cheered when Trinity in The Matrix used nmap and ssh (and so did you). Then I cringed again when I saw that inevitably, Hollywood had decided that nmap was the thing to use for all its hacker scenes (see Bourne Ultimatum, Die Hard 4, Girl with Dragon Tattoo, The Listening, 13: Game of Death, Battle Royale, Broken Saints, and on and on). In Tron, the hacker was not supposed to be snooping around on a network; he was supposed to kill a process. So we went with posix kill and also had him pipe ps into grep. I also ended up using emacs eshell to make the terminal more l33t. The team was delighted to see my emacs performance -- splitting the editor into nested panes and running different modes. I was tickled that I got emacs into a block buster movie. I actually do use emacs irl, and although I do not subscribe to alt.religion.emacs, I think that's all incredibly relevant to the world of Tron.

13
13

I want to translate the Touhou games into cantonese and I have no idea where to even start. Have any of you made custom tables for foreign scripts? Apparently some people already translated the games into Thai and that sounds like a lot of work

14
31
15
102
submitted 4 days ago* (last edited 4 days ago) by Gjolin@lemmy.ml to c/programming@programming.dev

I have not used an IDE since I ditched Turbo Pascal in middle school, but now I am at a place where everyone and their mother uses VS Code and so I'm giving it a shot.

The thing is, I'm finding the "just works" mantra is not true at all. Nothing is working out of the box. And then for each separate extension I have to figure out how to fix it. Or I just give up and circumvent it by using the terminal.

What's even the point then?

IDK maybe its a matter of getting used to something new, but I was doing fine with just vim and tmux.

16
255
submitted 5 days ago* (last edited 5 days ago) by mac@programming.dev to c/programming@programming.dev
17
71
18
154
Programming Is Mostly Thinking (agileotter.blogspot.com)
19
120
20
30

I'll need to cite a couple of tweets, so instead of wasting 10 mins to copy paste the data to bibtex I created this script in 30 mins.

21
-5
submitted 4 days ago* (last edited 4 days ago) by timetokey@programming.dev to c/programming@programming.dev

Hey Community, I figured that I could strengthen existing automated unit test generation quality by integrating mutation testing results as a metric to determine the quality of my unit tests. Figured everyone should be unit testing their code now especially after the recent Crowdstrike fiasco.

Check it out here https://github.com/codeintegrity-ai/mutahunter

Please star if you like it :)

22
19
Toolbox languages (www.hillelwayne.com)
23
19
24
39

I just finished watching Why Google Stores Billions of Lines of Code in a Single Repository and honestly, while it looks intriguing, it also looks horrible.

Have you run into issues? Did you love it? How was it/

25
35
view more: next ›

Programming

16397 readers
50 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS