Microsoft Offers Rust For Windows
Written by Mike James   
Monday, 19 April 2021

Rust seems to be the great saviour of programming at the moment and Microsoft is the latest to jump on the bandwagon with Rust for Windows.

rust

I'm not saying that jumping on the Rust bandwagon is a bad thing, but Microsoft makes an interesting travel companion. In the recent Microsoft world there were only two languages - C++ as a systems programming language and C# for everything else. After the Windows 8 meltdown Microsoft became omnivorous when it came to languages - adopting JavaScript, Python and anything that came into view.

The question remains if Rust is just another language to add to the collection Microsoft thinks are OK to support. For example, there is the Get Started with series of tutorials - Get Started with - Python, Node.js, Android, C++, C#, Docker, PowerShell, Database and now Rust. However, in the middle of all of this is that piece of news that we now have Rust For Windows. This isn't just using Rust to develop some generic console program, but a project to present the Windows API to a Rust program via the windows crate. This seems to include everything from basic windowing functions to Xaml. This is all possible because of the Windows metadata project, which describes the API in a machine readable form which can automatically be converted into Rust:

That Microsoft might have a play around with Rust isn't a surprise, but this is the first time Microsoft has shown affection for a language that could replace C++ in building Windows and  many Windows tools and applications. There has been much recent talk about letting Rust into the Linux kernel, could it be that the Windows team is thinking the same thoughts? If past experience is anything to go by, they are probably closing ranks and defending C++ a vigorously as possible - still doesn't mean it won't happen.

On the other hand, you have to be slightly sad to see the first example on the Windows Rust site. It starts well enough:

fn main() -> windows::Result<()> {
    let doc = XmlDocument::new()?;
    doc.LoadXml("<html>hello world</html>")?;
    let root = doc.DocumentElement()?;
    assert!(root.NodeName()? == "html");
    assert!(root.InnerText()? == "hello world");

but then we crash into:

unsafe {
     let event = CreateEventW(std::ptr::null_mut(),
true, false, None); SetEvent(event).ok()?; WaitForSingleObject(event, 0); CloseHandle(event).ok()?; MessageBoxA(None, "Text", "Caption",
MESSAGEBOX_STYLE::MB_OK); }

There is little point in adopting Rust if you are going to have to resort to "unsafe" the first time anything looks tricky. Is Rust for Windows able to avoid unsafe enough of the time to make it worth considering. Interesting question...

rust

More Information

Rust for Windows, and the windows crate

windows-rs

Related Articles

Google Supports Rust For Android OS Development

Is Microsoft Planning To Replace Rust?

Rust 1.46 Adds New APIs

Amazon AWS Invests In Rust

Mozilla Layoffs - The Fallout

Rust Is A Top Twenty Language

Daily Rust Use Increases, Survey Finds

Rust 2018 Released To Improve Developer Productivity

Rust Survey Revelations

Rust Is Safer But Do We Use It Safely

Is Rust Really Safe?

Oxide - A Simpler Formalized Rust

Rust Gets Async-Await

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Google Bans Program - Devs Suffer With No Redress
28/04/2021

This is a story I grow tired of writing, but until something changes I have no option but than continue to report it. No matter what you think of the app stores, their monopolies are bad for business. [ ... ]



New Spectre-Like Vulnerability - Is The Era Of Fast Clever Computers Over?
05/05/2021

Researchers have identified another speculative execution vulnerability and this one isn't fixed by the current OS patches. It seems very likely that the era of making processors faster by being cleve [ ... ]


More News

square

 



 

Comments




or email your comment to: comments@i-programmer.info

 

 

 

Last Updated ( Tuesday, 04 May 2021 )