Re: Converted my Go program to Rust

Liste des GroupesRevenir à cl misc 
Sujet : Re: Converted my Go program to Rust
De : rek2 (at) *nospam* hispagatos.org.invalid (rek2 hispagatos)
Groupes : comp.lang.misc alt.comp.lang.rust
Date : 04. Aug 2024, 17:24:14
Autres entêtes
Organisation : Hispagatos
Message-ID : <v8o6eu$1k6ob$2@matrix.hispagatos.org>
References : 1 2 3 4
User-Agent : slrn/pre1.0.4-9 (Linux)
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

Date Sujet#  Auteur
2 Aug 24 * Converted my Go program to Rust6rek2 hispagatos
2 Aug 24 `* Re: Converted my Go program to Rust5Lawrence D'Oliveiro
2 Aug 24  `* Re: Converted my Go program to Rust4rek2 hispagatos
4 Aug 24   `* Re: Converted my Go program to Rust3vallor
4 Aug 24    +- Re: Converted my Go program to Rust1rek2 hispagatos
5 Aug 24    `- Re: Converted my Go program to Rust1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal