Live data from Hacker News

The Dark Arts of Advanced and Unsafe Rust Programming

doc.rust-lang.org

21–26 of 26 posts

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#21
post #2

I recently had to write a lot of unsafe code in C# to interoperate with a driver. As advanced as modern languages are, the excellent memory models only work within the language. Interoperability requires that you can work with memory directly when needed. (And only when needed.) I don't have a lot of Rust experience, but C# has plenty of tricks to avoid unsafe code but get close enough to working with real memory. On…

There are many tools to generate C# bindings from header files. I haven't used one in a long time so can't remember any names but google and you will find. None of them are perfect so you always need to review the result and change some data types to more standard ones but at least it saves you writing the bulk of the code.

You usually run into the problem that the header files include other header files and you get this long dependency chain where somewhere in the chain some type is not recognized by the converter, to solve this the best is to cherry-pick the dependent types from the included header files and just put everything into one big flat header before passing into the tool. Macros can also be a PITA that you have to rewrite into functions and constants before generating.

You also have http://pinvoke.net/ with almost all win32 functions wrapped already. Same there though, review before use because it's a wiki and the quality is varying.

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#22
post #11

Earlier quoted context omitted.

> Rust is nothing but a slapdash C style copy of its semantics. Rust is a copy of Ada's semantics for dealing with memory unsafe code? Could you provide an example of what you mean? > Ada does, and has better and more clear conventions for "unsafe" programming (pointer arithmetic, conversions, etc) Can you give some examples here of what you mean? I found Interfaces.C.Pointers, but I don't know enough about the langu…

I meant Rust is a copy of Ada in general - it does not deal with unsafe programming in the same way. Instead, you do things like instantiate generic packages/procedure like Ada.Unchecked_Deallocation and Ada.Unchecked_Conversion with the specific conversion or heap deallocation procedure you need. So you are forced to be explicit about every unsafe operation by including such procedures and calling such things - but…

> I meant Rust is a copy of Ada in general

Have you ever actually looked at rust? The headline feature of Rust is linear types with checked borrowing, something that Ada does not provide.

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#23

Earlier quoted context omitted.

I meant Rust is a copy of Ada in general - it does not deal with unsafe programming in the same way. Instead, you do things like instantiate generic packages/procedure like Ada.Unchecked_Deallocation and Ada.Unchecked_Conversion with the specific conversion or heap deallocation procedure you need. So you are forced to be explicit about every unsafe operation by including such procedures and calling such things - but…

> I meant Rust is a copy of Ada in general Have you ever actually looked at rust? The headline feature of Rust is linear types with checked borrowing, something that Ada does not provide.

Plus Ada has a complicated runtime system that Rust doesn't.

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#24
post #2

I recently had to write a lot of unsafe code in C# to interoperate with a driver. As advanced as modern languages are, the excellent memory models only work within the language. Interoperability requires that you can work with memory directly when needed. (And only when needed.) I don't have a lot of Rust experience, but C# has plenty of tricks to avoid unsafe code but get close enough to working with real memory. On…

F# has a type provider system that can facilitate creation of such tools. And of course, it also has strong interoperability with C#.

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#25
post #23

Earlier quoted context omitted.

> I meant Rust is a copy of Ada in general Have you ever actually looked at rust? The headline feature of Rust is linear types with checked borrowing, something that Ada does not provide.

Plus Ada has a complicated runtime system that Rust doesn't.

Example?

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#26
post #12

It's a shame they didn't ever resume work on this. Apparently the guy who wrote it can't work on it any more

Thankfully, Gankro is now a colleague of mine and can work on it as much as they want again :)

omg does that mean Learning Rust With Entirely Too Many Linked Lists is going to get finished up at some point?
Post reply on HN