Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Andrea Giacobino
Andrea Giacobino

Posted on

     

Get the upstream distro name in Rust

The other day we were chatting with a colleague of mine about retrieving the OS name of the distribution. I don't recall exactly the details, but it was something about always getting the actual distribution name and not the upstream one, and he could not sort that out (I have my suspicions that he didn't try very hard).

Fast forward 2 weeks, I'm sipping coffee and installing updates on my laptop and suddenly this appears on the screen:

Alt Text

Oh, that's interesting 🤔, let's google "rust distribution id_like"?LMGTFY

BOOM! first result:https://docs.rs/os-release/0.1.0/os_release/struct.OsRelease.html

Looks good, let's give it a try:

> cargo new guess_os>cdguess_os> cargo add os-release> vim src/main.go
Enter fullscreen modeExit fullscreen mode

very well now let's add the code

externcrateos_release;useos_release::OsRelease;usestd::io;pubfnmain()->io::Result<()>{letrelease=OsRelease::new()?;println!("You say '{}', I say '{}'",release.name,release.id_like);Ok(())}
Enter fullscreen modeExit fullscreen mode

And now the moment of truth 🥁

asciicast

🏆

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I love to make useful stuff
  • Location
    Berlin
  • Joined

More fromAndrea Giacobino

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp