Rust Programming

8438 readers
38 users here now

founded 5 years ago
MODERATORS
301
4
This Week in Rust 439 (this-week-in-rust.org)
submitted 2 years ago by [email protected] to c/[email protected]
302
 
 

Rust is often described by its fans (me included) as the most advanced programming language, perfectly mixing Computer Science and real-world usability. Yet, Rust is far from perfect and may often be frustrating for developers.

So today, let's start from the axiom that Rust is the least bad programming language and what it would take to make it the "perfect" language and ecosystem.

303
 
 

This could be trash or not, but finished my first rust crate mailcap.

v0.1.0 is pretty much on par (as an example) with the functionality present in the python mailcap library in the stdlib. I noticed that there's no existing mailcap parsing crate in the rust ecosystem and had plans on actually creating a good custom opener (as my old python one is kinda hacky and well, obviously written when I was very new). So had to make the first step on the parser first before moving onto that.

Mailcap files are honestly much more flexible than .desktop files, as a single configuration file controls everything and it makes creating custom commands much easier. For example, I can specify easily a chain where gifs, despite being images, open in a video player with a custom command, while any other video or image default to something else.

image/gif; mpv --loop-file '%s' --loop=inf; test=test -n "$DISPLAY"
image/*; feh -g 1280x720 --scale-down '%s'; test=test -n "$DISPLAY"
video/*; mpv '%s'; test=test -n "$DISPLAY"

For a quick primer on what the opener would be that justifies this crate, what I use the python one for is setting it as my opener for any software which allows that to be changed (e.g. nnn, alacritty keyboard shortcuts) and overriding XDG_OPENER through a .desktop file. With the above example, any gif will open in mpv and loop infinitely, any other image will open in feh, while any video opens in mpv. The standard ~/.config/mimeapps.list does not support wildcards, and having to create custom .desktop files for variations such as the above is a much greater hassle.

Another plus is specifically for web URLs. The default behavior will be to open in a browser, while using something powered by a mailcap file makes that much more flexible. For example in my current python implementation, seeing the extension for a direct link to a file (e.g. my avi https://lemmygrad.ml/pictrs/image/H7j8YOJVDZ.png) will set this the mime type to image/png, and with the above mailcap example, will default to 'image/*' and open up the image in feh instead of a browser. And given that this is a custom opener, I use domain matching for sites such as gfycat to open in mpv.

The above two paragraphs are out of scope for this crate itself, but just wanted to give context on why I began work on it. I'm new to rust, but I hope this initial release is decent!

srht project page: https://sr.ht/~savoy/mailcap/

304
 
 

Out of the 58 in-the-wild 0-days for the year, 39, or 67% were memory corruption vulnerabilities. Memory corruption vulnerabilities have been the standard for attacking software for the last few decades and it’s still how attackers are having success. Out of these memory corruption vulnerabilities, the majority also stuck with very popular and well-known bug classes:

  • 17 use-after-free
  • 6 out-of-bounds read & write
  • 4 buffer overflow
  • 4 integer overflow
305
5
This Week in Rust 438 (this-week-in-rust.org)
submitted 2 years ago by [email protected] to c/[email protected]
306
307
308
 
 

Nushell, or Nu for short, is a new shell that takes a modern, structured approach to your commandline. It works seamlessly with the data from your filesystem, operating system, and a growing number of file formats to make it easy to build powerful commandline pipelines.

Today, we're releasing version 0.61 of Nu. This release includes UI improvements, many bugfixes, improved glob support, and more.

309
 
 

I'd like to share a side-project that I finally got to a minimally-useful state this weekend, in case others find it useful

Repository: https://gitlab.com/jokeyrhyme/xdp-hook-rs

Features (as of 0.1.2):

  • monitors Location, ScreenCast, and RemoteDesktop portal sessions
  • triggers configured scripts/command when these sessions are created/closed

Example use case:

  • I'm using eww as my status bar across the top of my screen
  • I wanted to show/hide indicators whenever an application was using the ScreenCast portal (e.g. https://meet.jit.si/ or Zoom, or Teams, or whatever)
  • so I'm using xdp-hook to detect when any application creates a ScreenCast session, and update the state in eww accordingly so that a blinking widget is displayed/removed

Suggestions and code contributions are welcome :)

310
311
312
11
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]
 
 

I've just published the stable version of pict-rs 0.3, and included a short write-up in the release description. Not much has changed since I posted about the betas, but check out the release anyway!

313
314
315
5
This Week in Rust 436 (this-week-in-rust.org)
submitted 2 years ago by [email protected] to c/[email protected]
316
 
 

I'm wondering if I should use Diesel in my project. I feel more comfortable writing SQL directly because I've used it before, but I've never done a database migration, I always deleted the database when I had to change it. So I don't know if I should learn Diesel to get migrations automatically or learn to do them directly in SQL. What would you recommend?

317
11
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]
 
 

I don't know how to choose a templating engine. They all seem the same to me. What are the differences between askama, tera, handlebars? Are there any others?

318
319
320
321
322
 
 

I'm playing with the following code and can't seem to find an example where I can get the values of one of the coordinates.

enum Coordinates {
    Point1 { x: i32, y: i32 },
    Point2 { x: i32, y: i32 },
}
fn main() {
    let p1 = Coordinates::Point1{ x: 0, y: 45};
    let x = p1.x; //Doesn't work
}

How can I get the value of x or y?

323
324
325
view more: ‹ prev next ›