Feed aggregator

Abstract space light [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:19pm
1280x720 2560x1440

Space art background [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:18pm
1280x720 2560x1440

Rainbow colourful galaxy wallpaper [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:17pm
1280x720 2560x1440

Beautiful lake wallpaper [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:15pm
1280x720 2560x1440

Fantasy night wallpaper [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:14pm
1280x720 2560x1440

Beautiful lightning background [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:13pm
1280x720 2560x1440

Dark night wallpaper [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:11pm
1280x720 2560x1440

Beautiful landscape wallpaper [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:10pm
1280x720 2560x1440

Abstract smoke wallpaper [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 3:07pm
1280x720 2560x1440

Fantasy sea view wallpaper [Wallpapers KDE Plasma]

KDE Store - Thu, 2024/08/01 - 11:13am
1280x720 2560x1440

More Ways to Rust

Planet KDE - Thu, 2024/08/01 - 7:35am

In our earlier blog, The Smarter Way to Rust, we discuss why a blend of C++ and Rust is sometimes the best solution to building robust applications. But when you’re merging these two languages, it’s critical to keep in mind that the transition from C++ to Rust isn’t about syntax, it’s about philosophy.

Adapting to Rust’s world view

If you’re an experienced C++ developer who is new to Rust, it’s only natural to use the same patterns and approaches that have served you well before. But problem-solving in Rust requires a solid understanding of strict ownership rules, a new concurrency model, and differences in the meaning of “undefined” code. To prevent errors arising from an overconfident application of instinctual C++ solutions that don’t align with Rust’s idioms, it’s a good idea to start by tackling non-critical areas of code. This can give you room to explore Rust’s features without the pressure of potentially bringing critical systems crashing down.

Maximizing performance in a hybrid application

Performance is often a concern when adopting a new language. Luckily, Rust holds its own against C++ in terms of runtime efficiency. Both languages compile to machine code, have comparable runtime checks, don’t use run-time garbage collection, and share similar back-ends like GCC and LLVM. That means that in most real-world applications, the performance differences are negligible.

However, when Rust is interfaced with C++ via a foreign function interface (FFI), there may be a noticeable overhead. The FFI disrupts the optimizer’s ability to streamline code execution on both sides of the interface. Keep this in mind when structuring your hybrid applications, particularly in performance-critical sections. You could use link-time optimization (LTO) in LLVM to help with this, but the additional complexity of maintaining this solution makes it a consideration only if profiling/benchmarking points to FFI being a main source of overhead.

Embracing ‘unsafe’ Rust

The normal approach for Rust is to eliminate code marked as ‘unsafe’ as much as possible. While both C++ and ‘unsafe’ Rust allow for pointer dereferencing that can potentially crash, the advantage in Rust is that this keyword makes issues easier to spot. ‘Unsafe’ Rust pinpoints where safety compromises are made, highlighting manageable risk areas. This in turn streamlines code reviews and simplifies the hunt for elusive bugs.

Bridging Rust with C/C++

Connecting Rust and C/C++ is clearly required when building hybrid applications. Thankfully, there’s a rich ecosystem of tools to support this:

  • Rust’s built-in extern “C” for straightforward C FFI needs
  • bindgen and cbindgen for generating bindings between Rust and C/C++
  • CXX and AutoCXX for robust, safe interoperability between the two environments
  • CXX-Qt for mixing Rust and Qt C++

Each tool serves a distinct purpose and choosing the right one can make the difference between a seamless integration and a complicated ball of compromises. (We provide more detailed guidance on this topic in our Hybrid Rust and C++ best practice guide, and my colleague Loren has a three part blog series that talks about this topic too: part 1, part 2, part 3.)

Adopting the microservice model

In complex applications with interwoven parts, it’s probably best to keep Rust and C++ worlds distinct. Taking a cue from the microservices design pattern, you can isolate functionalities into separate service loops on each side, passing data between them through well-defined FFI calls. This approach circumvents issues of thread blocking and data ownership, shifting focus from direct code calls to service requests.

Navigating Rust ABI dynamics

Rust does not guarantee a stable ABI between releases, which influences how you must design and compile your applications. To prevent breaking the build, create statically linked executables or use C FFIs for shared libraries and plugins, ensure that your entire project sticks to a consistent Rust version, and encapsulate all dependencies behind a C FFI.

Choosing the right build system

Building hybrid applications requires a thoughtful approach to choose a build system that will work well for the code you have and adapt easily as your program evolves.

  • Start with Cargo (provided by the Rust environment) for Rust-centric projects with minimal C++ code.
  • Switch to CMake if C++ takes on a more significant role.
  • Consider Bazel or Buck2 build systems for handling complex, language-agnostic build processes.

If you’re considering a custom build system, closely examine the available options first. With the breadth of today’s build tool landscape, it’s usually overkill to invent your own solution.

Summary

By understanding the challenges and employing the right strategies, C++ developers can smoothly transition to Rust, leveraging the strengths of both languages to build robust and efficient applications. For more information on this trending topic, you’ll want to consult our Hybrid Rust and C++ best practice guide, which was created in collaboration with Ferrous Systems co-founder Florian Gilcher.

About KDAB

If you like this article and want to read similar material, consider subscribing via our RSS feed.

Subscribe to KDAB TV for similar informative short video content.

KDAB provides market leading software consulting and development services and training in Qt, C++ and 3D/OpenGL. Contact us.

The post More Ways to Rust appeared first on KDAB.

Colorful-Dark-Global-6 [Global Themes (Plasma 6)]

KDE Store - Thu, 2024/08/01 - 6:49am
[COLOR="#4e51ac"] [B]Colorful[/B] [/COLOR] [COLOR="#008080"] [B]Dark[/B] [/COLOR] [COLOR="#aa55ff"] [B]Global[/B] [/COLOR] [COLOR=#0079b5"]...

Magna-Dark-Global-6 [Global Themes (Plasma 6)]

KDE Store - Thu, 2024/08/01 - 6:49am
[COLOR="#4e51ac"] [B]Magna[/B] [/COLOR] [COLOR="#008080"] [B]Dark[/B] [/COLOR] [COLOR="#aa55ff"] [B]Global[/B] [/COLOR] [COLOR=#0079b5"] [B]Theme...

Infinity-Global-6 [Global Themes (Plasma 6)]

KDE Store - Thu, 2024/08/01 - 6:48am
Dark Global Theme, Transparent and Blur For Plasma 6 -------------------------- Icons for Dark Plasma Themes [COLOR="blue"]...

Gently-Dark-Global-6 [Global Themes (Plasma 6)]

KDE Store - Thu, 2024/08/01 - 6:47am
Very Transparent and Blur Plasma Theme. Enabled Blurred Widgets and Adaptive Transparency ----------------------- [COLOR="#530053"]...

Relax-Light-Global-6 [Global Themes (Plasma 6)]

KDE Store - Thu, 2024/08/01 - 6:47am
Light Global Theme, Transparent and Blur -------------------------- Icons for Light Plasma Themes [COLOR="blue"] [B]Relax-Light-Icons[/B]...

Windows 7 Kvantum [Kvantum]

KDE Store - Thu, 2024/08/01 - 5:46am
This is a port of the Windows 7 widgets to kvantum

MOYASH Pixel Cursor [Cursors]

KDE Store - Thu, 2024/08/01 - 3:35am
MOYASH Pixel Cursor Theme. - Fixed Size: 32 x32 px. - 14 Colors. - for Linux and all Windows OS. ----- * [url="https://ko-fi.com/moyash"]Buy Me a...

Nordic darker KDE [Global Themes (Plasma 5)]

KDE Store - Thu, 2024/08/01 - 2:46am
Nordic darker is a dark theme created using the awesome [url=https://github.com/arcticicestudio/nord]Nord[/url] color palette. Suggested...

Nordic darker KDE [Plasma Themes]

KDE Store - Thu, 2024/08/01 - 2:46am
Nordic is a dark theme created using the awesome [url=https://github.com/arcticicestudio/nord]Nord[/url] color palette. Suggested settings:...