qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [Qemu-block] [RFC for-3.0 0/4] block: Add qcow2-rust bl


From: Max Reitz
Subject: Re: [Qemu-devel] [Qemu-block] [RFC for-3.0 0/4] block: Add qcow2-rust block driver
Date: Sat, 22 Apr 2017 18:42:12 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0

On 21.04.2017 17:51, Stefan Hajnoczi wrote:
> On Sat, Apr 01, 2017 at 05:57:47PM +0200, Max Reitz wrote:
>> The issues of using C are well understood and nobody likes it. Let's use
>> a better language. C++ is not a better language, Rust is. Everybody
>> loves Rust. Rust is good. Rust is hip. It will attract developers, it
>> will improve code quality, it will improve performance, it will even
>> improve your marriage. Rust is the future and the future is now.
>>
>> As the block layer, let's show our commitment to the future by replacing
>> one of our core parts, the the LEGACY (Bah! Yuck! Ugh!) qcow2 driver, by
>> a shiny (Oooh! Aaah!) Rust driver. Much better. My VMs now run thrice as
>> fast. Promise.
> 
> This is actually a good exercise.
> 
> Did you feel like there were places where Rust allowed you to express
> things better than C?

Well, I very much like the try!() macro and generally the fact that you
can return both a success and an error value at the same time.

(Which allowed me to represent the Error ** thing we generally use in a
much more natural way.)

> I like pattern matching, wish C had it.

That, including the (Haskell-like (?)) enums, is nice, too, yes.

I would like to say I hate that you have to explicitly cast integers
when converting between different widths, but if we had to do that in C,
it would have probably prevented quite some bugs we had in the past. (It
still is pretty annoying most of the time.)

Something that's not better than C but which surprised me in a really
positive way was how nice Rust's C interface is.


Having said that, there are things that really enrange me every time I
try my hands at Rust; most of which are intentional and probably
familiar to anyone having done so. But there are some things I have
missed for which there are proposed solutions, but they have been in a
"should be done soon" state for some years now.

For instance, when implementing methods for a generic type:

impl<T> BlockDriver<T> { ... }

you cannot test *whether* the type implements a certain trait.
https://github.com/XanClic/qemu/blob/rust-qcow2/block/rust/src/interface/mod.rs#L651
is where I complain.
You can implement functions only if T implements a trait:

impl<T: BlockDriverOpen> BlockDriver<T> {
    pub fn provides_open(&mut self) { ... }
}

But you cannot implement e.g. the same function but with a different
body (e.g. doing nothing) if T does not implement a trait, or provide a
generic implementation that is overwritten by these specialized
implementations. Both have been proposed and especially the first one is
supposed to be added in some form at some point in the future; but it
has been in that proposal state since 2014 or so...

(This is also a good thing, mind you, because it means they don't just
throw anything into the language just because it looks useful to
someone. They really think long and hard about what they add and what
implications it will have so it doesn't end up as a second C++.)


So all in all, Rust is not completely unusable, but of course you swear
a lot (at least I do) and it still feels kind of unfinished. I hate it
very much but at the same time, *for me*, I think it's the best language
for cases where I would have used C or C++ in the past.

Max

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]