Rust

7572 readers
1 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
101
 
 

Managarr v0.6.0 has been released with some fun new features!

Managarr is a terminal-based application for managing all your Servarr instances from one place. It provides a user-friendly interface to interact with your media libraries, making it easier to manage your downloads, monitor your series and movies, and perform various actions directly from the terminal.

It sports two modes: a TUI mode (Text User Interface) and a CLI mode (Command Line Interface).

TUI mode gives you an interactive User Interface right inside your terminal window, allowing you to navigate through your Sonarr and Radarr libraries, view details about your series and movies, and perform actions like adding or removing items, all through keyboard shortcuts.

CLI mode lets you execute commands directly from the terminal to manage your Servarr instances without needing to open the TUI. This is great for quick tasks or for integrating with scripts and automation tools.

The biggest change: Managarr now has themes!

The UI has been completely overhauled to support themes! You can now customize the look and feel of Managarr to suit your preferences. Choose from a variety of themes to change the color scheme and overall aesthetic of the application.

Here's just a few examples:

Default

default

Dracula

dracula

Watermelon Dark

watermelon-dark

You can also customize the themes to your heart's content! Check out the themes documentation for more details on how to create and apply your own themes.

Features

  • Added support for alternative Vim-like navigation keybindings (hjkl movements) Discussion #34
  • Added support for terminal-like backspace operations (Ctrl-h instead of Backspace)
  • You can now specify the number of downloads to fetch from the CLI: managarr <sonarr/radarr> list downloads --count 1234
  • You can now toggle movie monitoring from the CLI without needing to use the edit subcommand: managarr radarr toggle-movie-monitoring --movie-id 1234 #43
  • You can also now toggle series monitoring from the CLI without needing to use the edit subcommand: managarr sonarr toggle-series-monitoring --series-id 1234 #43
  • You can now also toggle movie/series monitoring directly from the Library view for each Servarr with the m key. No need to open the Edit [Series/Movie] modal anymore to simply toggle monitoring for an item! #43
  • Users can now skip up/down tables 20 items at a time using Ctrl-d and Ctrl-u keys (mirroring the same functionality in the Helix editor). Alternatively, the standard PgUp and PgDown keys are supported for the same operation. This is particularly useful for large libraries with many items #45
  • The total disk usage for any given series is now displayed in the Series Library view to mirror Radarr functionality #44
  • All keybindings and help tips have been refactored into a unified, dynamic menu that displays the available keybindings for the current view. This is accessible by pressing ? in any view, and it will display the keybindings relevant to that view. #32
  • Users can now add any number of custom headers to each Servarr's configuration, enabling support for OAuth and other custom authentication schemes for Servarr access #47

Fixes

  • Fixed a bug that caused the Collection Details modal to vanish when attempting to add a new film to a collection
  • Fixed a bug that caused the Radarr library to be rendered, then the Collections table to be rendered over it (merging the two), and then showing a popup which made for ugly and confusing UI
  • Wrapped Season.statistics with Option to prevent a panic if the season doesn't have any statistics (edge-case, only happens with outdated Sonarr data) #35
  • Corrected a bug that caused double key presses on Windows machines #40 (Thanks @cwesleys!)
  • Defaulted to empty tags to improve fault tolerance within the Sonarr and Radarr UIs. This is in response to #42, #48. It seems like this may be a bug in Sonarr where a series can have an associated tag ID but that tag Id doesn't exist in the list of tags, but I still can't quite track it down.
  • Fixed an issue that caused some panics to occur when video codecs are undefined in file metadata #38
  • More than 10 downloads will be listed in the Downloads tabs for both Radarr and Sonarr
  • Fixed a bug where Sonarr would have empty values on season releases for seeders/leechers instead of '0'
  • Fixed a bug where some Radarr films don't have studios associated with them, so the studio field is now nullable, preventing crashes when loading the Radarr library

Security Fixes

Minor Changes

  • Due to the new support for Vim-like navigation keybindings, the system logs are now opened using L instead of l
  • Refactored the network module to be more idiomatic Rust and to improve maintainability

Documentation

  • Update README.md to remove the cheeky Try Before You Buy heading since some users reported it as misleading; i.e. they thought it meant Managarr cost money. Managarr is and always will be, free

As always, thank you to everyone who reported an issue or requested a feature! You all make it a LOT easier to keep up with breaking API and add new features. If you have any feedback or suggestions, please don't hesitate to open an issue or discussion on the GitHub repository.

102
 
 

Managarr v0.6.0 has been released with some fun new features!

Managarr is a terminal-based application for managing all your Servarr instances from one place. It provides a user-friendly interface to interact with your media libraries, making it easier to manage your downloads, monitor your series and movies, and perform various actions directly from the terminal.

It sports two modes: a TUI mode (Text User Interface) and a CLI mode (Command Line Interface).

TUI mode gives you an interactive User Interface right inside your terminal window, allowing you to navigate through your Sonarr and Radarr libraries, view details about your series and movies, and perform actions like adding or removing items, all through keyboard shortcuts.

CLI mode lets you execute commands directly from the terminal to manage your Servarr instances without needing to open the TUI. This is great for quick tasks or for integrating with scripts and automation tools.

The biggest change: Managarr now has themes!

The UI has been completely overhauled to support themes! You can now customize the look and feel of Managarr to suit your preferences. Choose from a variety of themes to change the color scheme and overall aesthetic of the application.

Here's just a few examples:

Default

default

Dracula

dracula

Watermelon Dark

watermelon-dark

You can also customize the themes to your heart's content! Check out the themes documentation for more details on how to create and apply your own themes.

Features

  • Added support for alternative Vim-like navigation keybindings (hjkl movements) Discussion #34
  • Added support for terminal-like backspace operations (Ctrl-h instead of Backspace)
  • You can now specify the number of downloads to fetch from the CLI: managarr <sonarr/radarr> list downloads --count 1234
  • You can now toggle movie monitoring from the CLI without needing to use the edit subcommand: managarr radarr toggle-movie-monitoring --movie-id 1234 #43
  • You can also now toggle series monitoring from the CLI without needing to use the edit subcommand: managarr sonarr toggle-series-monitoring --series-id 1234 #43
  • You can now also toggle movie/series monitoring directly from the Library view for each Servarr with the m key. No need to open the Edit [Series/Movie] modal anymore to simply toggle monitoring for an item! #43
  • Users can now skip up/down tables 20 items at a time using Ctrl-d and Ctrl-u keys (mirroring the same functionality in the Helix editor). Alternatively, the standard PgUp and PgDown keys are supported for the same operation. This is particularly useful for large libraries with many items #45
  • The total disk usage for any given series is now displayed in the Series Library view to mirror Radarr functionality #44
  • All keybindings and help tips have been refactored into a unified, dynamic menu that displays the available keybindings for the current view. This is accessible by pressing ? in any view, and it will display the keybindings relevant to that view. #32
  • Users can now add any number of custom headers to each Servarr's configuration, enabling support for OAuth and other custom authentication schemes for Servarr access #47

Fixes

  • Fixed a bug that caused the Collection Details modal to vanish when attempting to add a new film to a collection
  • Fixed a bug that caused the Radarr library to be rendered, then the Collections table to be rendered over it (merging the two), and then showing a popup which made for ugly and confusing UI
  • Wrapped Season.statistics with Option to prevent a panic if the season doesn't have any statistics (edge-case, only happens with outdated Sonarr data) #35
  • Corrected a bug that caused double key presses on Windows machines #40 (Thanks @cwesleys!)
  • Defaulted to empty tags to improve fault tolerance within the Sonarr and Radarr UIs. This is in response to #42, #48. It seems like this may be a bug in Sonarr where a series can have an associated tag ID but that tag Id doesn't exist in the list of tags, but I still can't quite track it down.
  • Fixed an issue that caused some panics to occur when video codecs are undefined in file metadata #38
  • More than 10 downloads will be listed in the Downloads tabs for both Radarr and Sonarr
  • Fixed a bug where Sonarr would have empty values on season releases for seeders/leechers instead of '0'
  • Fixed a bug where some Radarr films don't have studios associated with them, so the studio field is now nullable, preventing crashes when loading the Radarr library

Security Fixes

Minor Changes

  • Due to the new support for Vim-like navigation keybindings, the system logs are now opened using L instead of l
  • Refactored the network module to be more idiomatic Rust and to improve maintainability

Documentation

  • Update README.md to remove the cheeky Try Before You Buy heading since some users reported it as misleading; i.e. they thought it meant Managarr cost money. Managarr is and always will be, free

As always, thank you to everyone who reported an issue or requested a feature! You all make it a LOT easier to keep up with breaking API and add new features. If you have any feedback or suggestions, please don't hesitate to open an issue or discussion on the GitHub repository.

103
10
submitted 3 months ago* (last edited 3 months ago) by ildar@programming.dev to c/rust@programming.dev
 
 

New (conference?) video presentation about the topic from Jane Street

104
 
 

I have been using thiserror, and somtimes snafu, for error handling in libraries and anyhow for error handling in applications.

This blog post describes a new library, Stackerror, that looks interesting. The post also gives a good overview of error handling in Rust.

105
 
 

We've been making good progress towards running more tests for rustc_codegen_gcc in the CI of the Rust repo to make our syncs with it easier and also progress towards having rustup distribution.

106
 
 

This releases includes some pretty nice improvements to the usage of the crate.

If you want to know how the View types I talk about in the release post are built, take a look at my post from back when I contributed them:

https://sgued.fr/blog/heapless-howto/

107
108
109
 
 

cross-posted from: https://lemmy.world/post/34689167

Wrote this TUI in Rust, using ratatui.

I just finished a first version of a personal project which I think is pretty cool, posting to get feedback and maybe others can enjoy using it too - omaro.

It's a TUI for lobste.rs, with vim-like (and regular) keybindings, mouse support, UI configuration, locally-saved read state for posts, and more. Check out the repo for more details.

Let me know what you think! Any feedback is appreciated.

110
111
14
This Week in Rust 612 (this-week-in-rust.org)
submitted 4 months ago by cm0002@piefed.world to c/rust@programming.dev
112
 
 

What’s new:

  • UTF-32 support
  • Optional serde support
  • 7-bit encoded unsigned integers like in .Net of all known fixed sizes
  • 7bit encoded u32 can be used as a size, to parse .Net strings
  • Unified implementation.

More is coming

https://crates.io/crates/deku_string

113
 
 
114
115
 
 

Hi everyone, I recently created an in-memory cache in Rust called PaperCache. It's the first in-memory cache that's able to switch between any eviction policy at runtime, allowing it to reduce its miss ratio by adapting to changing workloads. Currently, it supports the following eviction policies:

  • LFU
  • FIFO
  • CLOCK
  • SIEVE
  • LRU
  • MRU
  • 2Q
  • ARC
  • S3-FIFO

It typically has lower tail latencies than Redis (though with the trade-off of higher memory overhead as it needs to maintain extra metadata to be able to switch between policies at runtime).

Feel free to check out the website (https://papercache.io/) which has documentation, a high-level article I wrote on Kudos (https://link.growkudos.com/1f039cqaqrk), or the paper from HotStorage'25 (https://dl.acm.org/doi/abs/10.1145/3736548.3737836)

Here's a direct link to the cache internals: https://github.com/PaperCache/paper-cache

In case you want to test it out, you can find installation instructions here: https://papercache.io/guide/getting-started/installation

There are clients for most of the popular programming languages (https://papercache.io/guide/usage/clients), though some may be a little unpolished (I mainly use the Rust client for my own work, so that one is kept up-to-date).

If you have any feedback, please let me know!

116
117
118
119
120
 
 

After sketching a few designs and digging into Rust Atomics and Locks: Low-Level Concurrency in Practice by Mara Bos, I’ve finally locked down the Node component of the allocator.

The Node represents the smallest memory unit the allocator operates on. It holds the pointer to the memory chunk to be handed out.

I’ve benchmarked this at around 200 nanoseconds, compared to 2000+ nanoseconds for Windows’ HeapAlloc. By bypassing a context switch on my machine, the Node allocation logic gives a 10× speed-up, which is huge.

This is the only finalized part so far, but I’ll update benchmarks as other components come together. There’s still more testing to do and more structs to define for broader allocator functionality.

For now, I’m sharing a full screenshot of this section of code. The project is proprietary (not something I intend to police) if someone replicates it, but because of that, I won’t be publishing the complete codebase. Future examples will lean illustrative rather than literal.

That being said this isn’t the code verbatim either but it’s a lot of it and gives the whole mechanics of how a node allocates data and tracks meta. Hope this helps others ❤️

#[derive(Debug)]
pub struct Node<const HEADER_LEN: usize, const DATA_LEN: usize, const BUFFER_LEN: usize> {
    header: [u8; HEADER_LEN],
    data: [u8; DATA_LEN],
}

impl<const HEADER_LEN: usize, const DATA_LEN: usize, const BUFFER_LEN: usize>
    Node<HEADER_LEN, DATA_LEN, BUFFER_LEN>
{
    #[inline]
    pub fn write_header_info_ptr<P>(
        &mut self,
        position_begin_as_usize: usize,
        type_as_ptr: *const P,
    ) -> usize {
        let position_end_as_usize = position_begin_as_usize + SYS_POINTER_WIDTH;
        let type_as_usize = type_as_ptr as usize;
        let type_as_byte_array = type_as_usize.to_ne_bytes();
        let type_as_byte_slice = type_as_byte_array.as_slice();
        let writable_header_section =
            &mut self.header[position_begin_as_usize..position_end_as_usize];

        writable_header_section.copy_from_slice(type_as_byte_slice);
        position_end_as_usize
    }

    #[inline(always)]
    pub fn read_header_info_ptr<P>(&self, position_begin_as_usize: usize) -> (usize, NonNull<P>) {
        let position_end_as_usize = position_begin_as_usize + SYS_POINTER_WIDTH;
        let readable_header_section = &self.header[position_begin_as_usize..position_end_as_usize];
        let mut result_buf = [0u8; SYS_POINTER_WIDTH];

        result_buf.copy_from_slice(readable_header_section);

        let addr = usize::from_ne_bytes(result_buf);
        let type_as_ptr = addr as *const P;

        (position_end_as_usize, unsafe {
            NonNull::new_unchecked(type_as_ptr as *mut P)
        })
    }

    pub fn aligned_addr(&mut self, align: usize) -> Option<NonNull<u8>> {
        let data_as_mut_ptr = self.data.as_mut_ptr();
        let word_offset_as_mut_ptr = unsafe { data_as_mut_ptr.add(SYS_POINTER_WIDTH) };

        let align_offset = word_offset_as_mut_ptr.align_offset(align);
        let align_offset_as_mut_ptr = unsafe { word_offset_as_mut_ptr.add(align_offset) };

        unsafe {
            let header_as_ptr = &self.header as *const [u8; HEADER_LEN];
            let header_as_usize = header_as_ptr as usize;
            let header_as_byte_array = header_as_usize.to_ne_bytes();
            let header_as_byte_slice = header_as_byte_array.as_slice();
            let write_header = align_offset_as_mut_ptr.sub(SYS_POINTER_WIDTH) as *mut u8;
            let write_buf = slice::from_raw_parts_mut(write_header, SYS_POINTER_WIDTH);

            write_buf.copy_from_slice(header_as_byte_slice);
        }

        NonNull::new(align_offset_as_mut_ptr)
    }

    pub fn resolve_addr(
        position_begin_as_usize: usize,
        ptr: *mut u8,
        head: *mut Self,
    ) -> NonNull<Self> {
        let position_end = SYS_POINTER_WIDTH + position_begin_as_usize;
        let header_as_ptr = unsafe { ptr.sub(SYS_POINTER_WIDTH) };
        let header_as_slice = unsafe { slice::from_raw_parts(header_as_ptr, SYS_POINTER_WIDTH) };
        let mut header_as_array = [0u8; SYS_POINTER_WIDTH];

        header_as_array.copy_from_slice(header_as_slice);

        let header_as_usize = usize::from_ne_bytes(header_as_array);
        let header_as_mut_ptr = header_as_usize as *mut [u8; HEADER_LEN];
        let header_as_slice = unsafe { &*header_as_mut_ptr };
        let node_as_slice = &header_as_slice[position_begin_as_usize..position_end];
        let mut node_buf_array = [0u8; SYS_POINTER_WIDTH];

        node_buf_array.copy_from_slice(node_as_slice);

        let node_as_usize = usize::from_ne_bytes(node_buf_array);
        let node_as_ptr = node_as_usize as *const Self;

        unsafe {
            let head_as_usize = head as usize;
            let head_as_byte_array = head_as_usize.to_ne_bytes();
            let head_as_byte_slice = head_as_byte_array.as_slice();
            let header_as_mut_ref = &mut *header_as_mut_ptr;
            let header_first_word_as_mut_slice =
                &mut header_as_mut_ref[SYS_POINTER_WIDTH * 7..SYS_POINTER_WIDTH * 8];

            header_first_word_as_mut_slice.copy_from_slice(head_as_byte_slice);
        }

        unsafe { NonNull::new_unchecked(node_as_ptr as *mut _) }
    }
}
121
 
 

However, there are some important features that WinSock just doesn’t expose. […]

Rust’s current async ecosystem is built atop a particularly cursed concept. It’s an unstable, undocumented Windows feature. It’s the lynchpin of not only the Rust ecosystem, but the JavaScript one as well. It’s controversial. It’s efficient. […] Without it, it’s unlikely that the async ecosystem would exist in its current form. It’s called \Device\Afd, and I’m tired of no one talking about it.

122
 
 

So I've been writing an allocator. A difficult task and in Rust it is currently a dream to write.

The patterns I'm on about are small quick scopes to get a mutable reference and store or read data.

pub fn some_func(&mut self, s: &[u8]) {
    // Mutable borrow 1 and write
    {
        let writable = &mut self.buf[..8];

        writable[..8].copy_from_slice();
    }

    // Mutable borrow 2 and write
    {
        let writable = &mut self.buf[8..16];

        writable[8..16].copy_from_slice();
    }

    // And so on . . .
}

No other language feels like this. No other language is so precise on reads and writes always taking a length or the length can be obtained from the type (such as a slice).

Writing to different parts of a buffer and selecting parts of like this feels amazing. For writing an allocator i can just make array's and then write any bytes to them and just read them back and cast them about.

So much better than just using raw pointers, and safer as sizes are usually know with slices.

Anyway i just love Rust and this was an excuse to share my love of Rust <3

123
124
 
 

Developer @tomtau@aussie.zone

https://pest.rs/book/examples/awk.html 🎉

I aimed to keep it in line with the "demonstration of the Rust ecosystem" goal, so it can also be a great introduction to Rust for beginners who are looking for a fun project to work on. It's not perfect, but that's part of the fun! It leaves room for potential language extensions (to make the AWK clone more complete) and optimizations up to the reader as a follow-up.

125
 
 
view more: ‹ prev next ›