Building GNOME Apps with Rust, Part 6: Fetching Feeds
This is Part 6 of a series taking a GNOME app from an empty directory to GNOME Circle. Part 5 wired the sidebar to a real Feed GObject and a feed-selected signal — selecting a row updates the content pane and prints a line to the terminal. This is the post where that line stops being a placeholder and becomes a real network fetch. The click that still does nothing real Select This Week in GNOME ,…
This sixth installment in the series of building a GNOME app from scratch outlines the process of fetching feeds using Rust. Previous parts have established a foundation for displaying feeds and handling user interactions. In this section, the author introduces two executors, GLib's main loop and Tokio's runtime, which will work together to allow the app to fetch network resources without freezing the UI.
To add the necessary dependencies, the author includes tokio, feed-rs, and reqwest crates in the Cargo.toml file. Tokio's rt-multi-thread feature is specified to create worker threads for handling blocking operations like network requests. reqwest, a Rust HTTP client library, is also included, with rustls-tls feature enabled to provide a pure-Rust TLS stack instead of linking against the system's OpenSSL.
The key to achieving non-blocking network fetches lies in the separation of concerns between the two executors. The GLib main loop, responsible for managing the application's widgets and signals, should never block. On the other hand, Tokio, a dedicated runtime for blocking operations such as network requests, handles these tasks on its own thread pool.
The two executors interact through a mechanism called .await, which allows a GLib main loop task to pause and await the completion of a Tokio future. Once the network request is finished, the result is made available to the GLib main loop, enabling the UI to update and display the fetched data without any freezing or flickering.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.