Deutsch   English   Français   Italiano  
<v8o6eu$1k6ob$2@matrix.hispagatos.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.hispagatos.org!.POSTED!not-for-mail
From: rek2 hispagatos <rek2@hispagatos.org.invalid>
Newsgroups: comp.lang.misc,alt.comp.lang.rust
Subject: Re: Converted my Go program to Rust
Date: Sun, 4 Aug 2024 15:24:14 -0000 (UTC)
Organization: Hispagatos
Message-ID: <v8o6eu$1k6ob$2@matrix.hispagatos.org>
References: <v8h1ct$1fe39$1@matrix.hispagatos.org>
 <v8h4gn$2e5g0$3@dont-email.me> <v8hd1g$1fk30$1@matrix.hispagatos.org>
 <v8nmtm$3neof$1@dont-email.me>
Reply-To: ReK2 <rek2@hispagatos.org>
Injection-Date: Sun, 4 Aug 2024 15:24:14 -0000 (UTC)
Injection-Info: matrix.hispagatos.org;
	logging-data="1710859"; mail-complaints-to="abuse@hispagatos.org"
User-Agent: slrn/pre1.0.4-9 (Linux)
Bytes: 3014
Lines: 57

On 2024-08-04, vallor <vallor@cultnix.org> wrote:
>
> I don't know Rust, so your program is a bit of an introduction.

I also started not far away a go, I come from C and GO.

> With that in mind, I wonder if this wouldn't be a little bit
> better:

Not a problem is why I link it to this newsgroup ;)

>  - -%<- cut here - -
> --- main.rs~	2024-08-04 03:44:07.000000000 -0700
> +++ main.rs	2024-08-04 03:45:19.824804343 -0700
> @@ -106,7 +106,7 @@
>      }
>  
>      // If the entry does not exist, append it to the file using SUPERUSER_CMD
> -    let update_hosts_command = format!("echo {} {}.htb | tee -a /etc/hosts", ip_address, box_name);
> +    let update_hosts_command = format!("echo {} | tee -a /etc/hosts", entry);
>      let mut command = Command::new(SUPERUSER_CMD);
>      command
>          .arg("sh")
>  - -%<- cut here - -
>
> Would that work?  If so, it would let you change the entry format
> in "entry" in only one place, if you decide to do so.

This indeed will save some lines of code, but from my security best
habits in coding I always try to limit the amount of stdin that can be 
added, so if I split variables I have a better way to handle each value
and avoid the user input to do things it was not supposed to.

> (Also, was intrigued by how "let" seems to work, if I understand it correctly.
> Will have to take a look at Rust!)

Yeah takes time to get used to the new wording and such but is nice when
you pick it up.

> Finally, I've long been disappointed that git doesn't preserve
> timestamps on files.  Does anyone know of any discussion about
> why that is, and perhaps changing git to have that capability?
>
> [ sorry about not honoring your fu2, my server doesn't seem to
> have alt.comp.lang.rust. ]

No problem you can always ask your news server admin to add it.
and I think it did came in to alt.comp.lang.rust I am reading it there.

Cheers
Happy Hacking
ReK2


-- 
- {gemini,https}://{,rek2.}hispagatos.org - mastodon: @rek2@hispagatos.space
- [https|gemini]://2600.Madrid            - https://hispagatos.space/@rek2
- https://keyoxide.org/A31C7CE19D9C58084EA42BA26C0B0D11E9303EC5