Earlier quoted context omitted.
To reply to both you and your parent at once, yes, the reason this is in the nursery is that it's not a complete resource yet. I agree that this particular example is bad; it's showing the right pattern for the wrong example. The right way is to use rayon, which is similar to OpenMP in this sense. Each thread would get a pointer to the chunk of the buffer it's operating on. You don't need to write any unsafe code to…
It's good to hear that there's an idiomatic Rust way of doing this that doesn't require unsafe but is still performant. I figured there was, but to an outsider it was not obvious how. This is not actually the first time I've seen this example code. I was wondering how Rust solved this issue (parallel rendering into a single framebuffer) in a way that satisfied the borrow checker, and came across this example. It was…
Writing a small ray tracer in Rust and Zig
81–90 of 98 posts
Re: Writing a small ray tracer in Rust and Zig
#82Earlier quoted context omitted.
To reply to both you and your parent at once, yes, the reason this is in the nursery is that it's not a complete resource yet. I agree that this particular example is bad; it's showing the right pattern for the wrong example. The right way is to use rayon, which is similar to OpenMP in this sense. Each thread would get a pointer to the chunk of the buffer it's operating on. You don't need to write any unsafe code to…
It's good to hear that there's an idiomatic Rust way of doing this that doesn't require unsafe but is still performant. I figured there was, but to an outsider it was not obvious how. This is not actually the first time I've seen this example code. I was wondering how Rust solved this issue (parallel rendering into a single framebuffer) in a way that satisfied the borrow checker, and came across this example. It was…
Re: Writing a small ray tracer in Rust and Zig
#83Earlier quoted context omitted.
To me, this somehow says that most truely interesting problems can only be solved efficiently in Rust using unsafe. Granted, my definition of interesting may be a bit limited, but my initial takeaway here is that Rusts safety story is much more limited than its proponents claim.
> To me, this somehow says that most truely interesting problems can only be solved efficiently in Rust using unsafe. Even Vec is implemented with unsafe code under the hood. Rust isn't about not using unsafe code anywhere : it's about encapsulating that unsafe code in reusable abstractions that can be easily audited. This is how essentially all languages work to begin with: unless you're using CompCert, the compiler…
Re: Writing a small ray tracer in Rust and Zig
#84Earlier quoted context omitted.
> To me, this somehow says that most truely interesting problems can only be solved efficiently in Rust using unsafe. Even Vec is implemented with unsafe code under the hood. Rust isn't about not using unsafe code anywhere : it's about encapsulating that unsafe code in reusable abstractions that can be easily audited. This is how essentially all languages work to begin with: unless you're using CompCert, the compiler…
Wait, so how exactly is Rust better than C++ again? If I need to bring my own unsafe code to the party, where is the gain? Especially, if - in your words - "This is how essentially all languages work to begin with". I can build "safe" abstractions in any other language, too, can I not?
Re: Writing a small ray tracer in Rust and Zig
#85> But rendering in separate threads turned out to be (unsurprisingly) harder than the way I would do it in C++...It was a bit frustrating to figure out how to accomplish this. Googling yielded a few stack overflow posts with similar questions, and were answered by people basically saying use my crate! Based on some discussion in r/rust ( https://www.reddit.com/r/rust/comments/c7t5za/writing_a_smal... ) I went ahead a…
I still don't understand why Rayon is not part of the Rust standard library. Rust was created to have easy and safe multithreading on the CPU, and Rayon is the clear winner in this space, for me it feels like something that should be part of Rust.
Re: Writing a small ray tracer in Rust and Zig
#86Earlier quoted context omitted.
unsafe is the tool u are looking for.
No, there are plenty of safe ways to achieve this in the standard library. The chunks and split families of functions on slices are all designed to do pretty much exactly this.
unsafe is the mechanism that GP needs to use to get multiple contiguous mutable borrows.
There is nothing wrong with unsafe, it is used to build all of the safe abstractions in Rust.
Re: Writing a small ray tracer in Rust and Zig
#87Earlier quoted context omitted.
unsafe is the tool u are looking for.
:(
Splitting a single slice into two mutable slices is done via https://doc.rust-lang.org/std/primitive.slice.html#method.sp... if you want more than that, you will need to roll your own.
I think it would be a great exercise to implement what you are asking for, the docs link directly to the source.
https://doc.rust-lang.org/src/core/slice/mod.rs.html#991-100...
Re: Writing a small ray tracer in Rust and Zig
#88Earlier quoted context omitted.
> To me, this somehow says that most truely interesting problems can only be solved efficiently in Rust using unsafe. Even Vec is implemented with unsafe code under the hood. Rust isn't about not using unsafe code anywhere : it's about encapsulating that unsafe code in reusable abstractions that can be easily audited. This is how essentially all languages work to begin with: unless you're using CompCert, the compiler…
Wait, so how exactly is Rust better than C++ again? If I need to bring my own unsafe code to the party, where is the gain? Especially, if - in your words - "This is how essentially all languages work to begin with". I can build "safe" abstractions in any other language, too, can I not?
Re: Writing a small ray tracer in Rust and Zig
#89Earlier quoted context omitted.
> To me, this somehow says that most truely interesting problems can only be solved efficiently in Rust using unsafe. Even Vec is implemented with unsafe code under the hood. Rust isn't about not using unsafe code anywhere : it's about encapsulating that unsafe code in reusable abstractions that can be easily audited. This is how essentially all languages work to begin with: unless you're using CompCert, the compiler…
Wait, so how exactly is Rust better than C++ again? If I need to bring my own unsafe code to the party, where is the gain? Especially, if - in your words - "This is how essentially all languages work to begin with". I can build "safe" abstractions in any other language, too, can I not?
And when you do decide you need to use `unsafe` for a non-FFI purpose, Rust provides the tooling to explicitly define the abstraction barrier such that clients of your code don't have to care (or even know) that you're using unsafe internally.
Re: Writing a small ray tracer in Rust and Zig
#90Earlier quoted context omitted.
The problem is that several of those standard library components are no longer recommended for general usage: * As with "syscall", users are strongly suggested to use "golang.org/x/crypto" for crypto primitives like AEAD. All of the crypto bits in the standard library are probably still "okay" but there are better interfaces and more efficient implementations in "golang.org/x/crypto". * The "flags" package is basical…
I agree and I'm not advocating for Rust's std to gain things like http clients or template engines. But some parts of the ecosystem end up in a lot of projects. Conservatively extending std would be good for the language, IMO. To set a standard, reduce compile times, and ease the burden for companies that have hard review requirements for each dependency. Some things I'd like to see in std in a few years: * `serde` *…