Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
Curious - how easy is Rust to integrate into F#/Unity?

Adbot
ADBOT LOVES YOU

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
You need to do this:

code:
fn reassign(x: &mut u32) {
    *x = 4;
}
You can't assign a u32 to a &u32, so you have to dereference it. It worked on a struct previously because "a.b" can be implicitly dereferenced to "(*a).b" if need be - this is so operations on references to structs aren't needlessly verbose, since they're very common.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
Speaking of error-chain, I started using the rust SDL 2 library, which returns some errors as Result<_, String>. What's the most idiomatic way of dealing with those? They work fine by themselves, but I'd like to chain_err them.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
It's saying that the Err type of Result needs to implement error::Error, though. I have an error module available, and I can chain_err on other Results as long as their Err implements error::Error. It's just the ones that return Strings instead of real errors that are causing problems.

e: For reference, just in case I'm being real stupid, here's some code that runs into this:

code:
# error.rs

error_chain! {}
code:
# lib.rs

#[macro_use]
extern crate error_chain;
extern crate sdl2;

pub mod errors;

use errors::*;

fn init() -> Result<()> {
    let sdl = sdl2::init().chain_err(|| "Initialization failed.")?;
    Ok(())
}
Where init() returns a Result<Sdl, String>.

Asymmetrikon fucked around with this message at 02:38 on Dec 9, 2016

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
Mapping errors sounds good, thanks. They not only use Strings for some errors (errors in init() and Sdl::video), they have an error type UpdateTextureError that doesn't implement Error? It's real weird. Probably going to see if they've done something about that and try to patch it otherwise.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
I think my least favorite thing about refactoring so far has been trying to isolate parts of a chain of iterators. The result of a .map().filter().whatever() has a gnarly result type.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
Filter is parameterized over a P: FnMut, which the compiler just represents as an anonymous closure, though. How do you express that kind of type concretely?

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!

gonadic io posted:

Will 'impl trait' help for this case?

Yeah. Is that out of nightly yet?

Adbot
ADBOT LOVES YOU

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
Has anyone used the Rust IntelliJ plugin with rustup? If so, how do you get it to find the standard library sources? It comes up with an option to download them, and I click on it and it doesn't error out or anything, and I can check that the rust-src component is installed and the rust sources are downloaded, but no matter what I do the plugin doesn't seem able to find them. Even if I manually point it at any of the folders in the source path, it says those are invalid.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply