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
gonadic io
Feb 16, 2011

>>=
Generalising the return type of main just got merged: https://github.com/rust-lang/rfcs/blob/master/text/1937-ques-in-main.md

Adbot
ADBOT LOVES YOU

xtal
Jan 9, 2011

by Fluffdaddy
That's dumb as hell

Workaday Wizard
Oct 23, 2009

by Pragmatica

xtal posted:

That's dumb as hell

Not really. It makes writing small programs easier and if you don't use it nothing changed for you anyway.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

xtal posted:

That's dumb as hell

Do you have any reasoning behind that hot take?

xtal
Jan 9, 2011

by Fluffdaddy

taqueso posted:

Do you have any reasoning behind that hot take?

The cost of calling unwrap or expect once is not worth this oddity which is unique across all programming languages I've used.

Workaday Wizard
Oct 23, 2009

by Pragmatica

xtal posted:

The cost of calling unwrap or expect once is not worth this oddity which is unique across all programming languages I've used.

How do Java, C#, Python, etc. report unhandled exceptions?

gonadic io
Feb 16, 2011

>>=

xtal posted:

The cost of calling unwrap or expect once is not worth this oddity which is unique across all programming languages I've used.

If you keep defining main() { then nothing will change.

VikingofRock
Aug 24, 2008





Awesome! This will make writing a lot of small programs and example code much cleaner.

Joe Law
Jun 30, 2008

xtal posted:

That's dumb as hell

The only thing I saw about it that seemed odd was this line:

quote:

Therefore I am proposing that all the standard impls' report functions should use 0 for success and 2 for failure.

I'm not sure I'm convinced by their explanation on why EXIT_FAILURE shouldn't just be 1.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
I'm playing with Rocket and Diesel -- they're the first real frameworks I've tried in rust (tokio is probably the largest library I've dealt with).

CodeGen and Macros are going to ruin this language.

http://docs.diesel.rs/diesel/macro.infer_table_from_schema.html

I'm flabbergasted that the compiler even makes this possible. I'm doubly flabbergasted that Diesel presents this in their tutorial as the way to generate their schema.

Eela6
May 25, 2007
Shredded Hen
Is there a good physical book about rust? I learn best just by reading paper.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

MALE SHOEGAZE posted:

I'm playing with Rocket and Diesel -- they're the first real frameworks I've tried in rust (tokio is probably the largest library I've dealt with).

CodeGen and Macros are going to ruin this language.

http://docs.diesel.rs/diesel/macro.infer_table_from_schema.html

I'm flabbergasted that the compiler even makes this possible. I'm doubly flabbergasted that Diesel presents this in their tutorial as the way to generate their schema.
Wow. I'm a big fan of powerful tools even if they can be abused, but I do not understand people who think doing network shenanigans at compiletime is a good idea.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
I think this is a pretty bad idea too but, to be fair, languages like Java do a ton of this stuff at compile time too, e.g. Jooq. What I dislike most about macro based DSLs is that inevitably they will end up like C++-style template monstrosities that are poorly documented and where there is no hope of sane autocompletion.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Sagacity posted:

I think this is a pretty bad idea too but, to be fair, languages like Java do a ton of this stuff at compile time too, e.g. Jooq. What I dislike most about macro based DSLs is that inevitably they will end up like C++-style template monstrosities that are poorly documented and where there is no hope of sane autocompletion.

What concerns me is that rust made this incredibly easy. Yes, I was importing a crate called `_codegen`, which should have tipped me off, but beyond that it's just a macro. If this were enabled as part of a plugin, it would be a different story. Macros should not be able to do this, and now I'm going to have to be incredibly suspicious of every single macro I encounter because it could be doing network insanity at compile time. (I could be mistaken about some of this, I haven't actually figured out how this macro works yet).

DONT THREAD ON ME fucked around with this message at 19:59 on Aug 12, 2017

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

MALE SHOEGAZE posted:

What concerns me is that rust made this incredibly easy. Yes, I was importing a crate called `_codegen`, which should have tipped me off, but beyond that it's just a macro. If this were enabled as part of a plugin, it would be a different story. Macros should not be able to do this, and now I'm going to have to be incredibly suspicious of every single macro I encounter because it could be doing network insanity at compile time. (I could be mistaken about some of this, I haven't actually figured out how this macro works yet).
"just a macro" can't do this. At a guess, the macro expands to a custom derive, which IIRC can run arbitrary code. Understanding what the macros you're using do is good practice regardless, of course.

Linear Zoetrope
Nov 28, 2011

A hero must cook

Ralith posted:

"just a macro" can't do this. At a guess, the macro expands to a custom derive, which IIRC can run arbitrary code. Understanding what the macros you're using do is good practice regardless, of course.

Yeah, if you look at the source you get this:

code:
macro_rules! infer_table_from_schema {
    ($database_url: expr, $table_name: expr) => {
        #[derive(InferTableFromSchema)]
        #[infer_table_from_schema_options(database_url=$database_url, table_name=$table_name)]
        struct __DieselInferTableFromSchema;
    }
}

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Weird, it never occurred to me that you could use custom derive like that.

I assume procedural macros will allow similar behavior? If so I really hope they gate them somehow because I really don't want things like this to be standard macro behavior. But to Ralith's point, it's not like I ever really use a macro without understanding what it does, so maybe it's okay.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
Procedural macros should generally be the exception, at least once declarative macros 2.0 lands. Hell, any kind of macros at all should be the rare exception, much less complicated ones. It's good to have escape hatches in a language, even if some people will always be tempted to treat the escape hatch more like a revolving door.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Ralith posted:

Procedural macros should generally be the exception, at least once declarative macros 2.0 lands. Hell, any kind of macros at all should be the rare exception, much less complicated ones. It's good to have escape hatches in a language, even if some people will always be tempted to treat the escape hatch more like a revolving door.

I think I've misunderstood the state of macros. My understanding was the procedurals macros were macros 2.0, but it sounds like you're saying that's not the case. Guess I have some reading to do.

gonadic io
Feb 16, 2011

>>=
I think the need for macros will go down a bit once const_fn is stable. Certainly that's what I mostly use them for myself.

Linear Zoetrope
Nov 28, 2011

A hero must cook

gonadic io posted:

I think the need for macros will go down a bit once const_fn is stable. Certainly that's what I mostly use them for myself.

And impl Trait, one of the areas I used macros the most is where I basically wanted to just treat heterogeneous objects as a uniform trait and a trait object was insufficient. (Such as selecting between and initializing different implementations of the same interface based on user input, and then doing the same thing to it regardless).

E:

Like

code:
let program_behavior = match InputEnum::from_args(blah) {
   Foo => { let mut foo = initialize_foo(other_args); 
            foo.more_setup();
            foo
           },
    Bar => initialize_bar(other_args), 
};

program_behavior.do_thing();
Couldn't do that before because you can't return a trait object for foo or bar without it going out of scope so you basically had to repeat the code for everything you wanted to do within the match or use a macro.

Linear Zoetrope fucked around with this message at 14:48 on Aug 14, 2017

Linear Zoetrope
Nov 28, 2011

A hero must cook
Does anyone know how to test libloading plugins? I have the following sort of thing:

[Generic language] -> Plugin Loader/Context manager/etc (extern C no mangle cdylib Rust crate that uses libloading) -> Rust plugins (no mangle dylib Rust crate)

I'd basically like to test the Plugin loader, but to do that I need a compiled plugin. I've screwed around with making a dylib plugin_test crate and putting it in dependencies and dev-dependencies, but I've crawled all around the target directory and it looks like if it's written in Rust it's automatically linked statically as a .rlib and there's no .dll/.so/.dylib in sight. Additionally, Cargo doesn't (yet) support test-specific build scripts.

It's not the end of the world to write some scripts to run on Travis/Appveyor that manually build a test crate and set some test environment variables, but I was hoping for something a bit more Cargo-friendly.

Love Stole the Day
Nov 4, 2012
Please give me free quality professional advice so I can be a baby about it and insult you
Did a bunch of tutorials and am mostly through the official Rust book. Really liking the convenience of "cargo build" and the .toml file as opposed to cmake, which has been my White Whale for many years because I am dumb and bad. It feels like a compromise between Javascript's npm stuff and C/C++'s make files.

Linear Zoetrope
Nov 28, 2011

A hero must cook
Cargo is easily Rust's best feature. Every time I have to dive back into C++ or Python land (and I'm a PhD student doing research work, so a lot of these aren't exactly... iron clad libraries) I end up with weird messes of dependency management. ESPECIALLY around the fuzzy OS-level boundaries where something works on one OS but suddenly the nice pip or setup.py or apt-get dependencies or whatever become a giant nightmare on OS X or Windows or not-Windows or Cent OS (but not Ubuntu) and so on. Rust doesn't prevent this, I've seen a few niche libraries that require some sys-type crates that they could only get working on one or two OS's or require installations of a language that are a pain to properly setup on Windows or something, but the mix of Cargo and Rust's general platform agnostic-ness makes it a hell of a lot less likely, and IME crate maintainers in Rust-land are much more likely to document these idiosyncrasies.

Rust isn't a perfect language, but once you learn how to cope with how long you spend before getting a large engineering effort to compile and how to deal with the corner cases where the borrow checker gets really stupid it's one of the most pleasant environments to work in.

(Also, I have to at least give a shoutout to Rust having very firm community guidelines wrt kindness, inclusiveness and recent initiatives to get women, transpeople, POC, etc into the core community with things like impl Future. It's really nice to know they're at least trying and it makes getting help with Rust way less draining.)

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Just wanted to mention that Firefox beta channel now has Quantum, which includes Servo, which means that in a couple of weeks hundreds of millions of people are going to be running Rust code on their desktops all day, for better performance.

pseudorandom name
May 6, 2007

Firefox has been shipping a Rust MP4 container parser for a while now.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Oh, I forgot about that!

Love Stole the Day
Nov 4, 2012
Please give me free quality professional advice so I can be a baby about it and insult you
What do you guys recommend for GUI crates? I've heard good things about using GTK bindings for Rust but since I'm using Windows and MSVC it looks like I'd have to go out of my way to do everything in a separate IDE or whatever. Tried Googling it but I don't see any simple solution, but maybe I'm just bad and dumb.

I learned about the Rocket crate recently and think it might be a good exercise to try to do for a web project.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
GTK bindings don't care what IDE you use, but GTK on windows is pretty terrible. Rust doesn't really have any mature GUI stuff yet; you could try a web UI instead.

Linear Zoetrope
Nov 28, 2011

A hero must cook
Non-lexical borrow scopes are finally under review

Love Stole the Day
Nov 4, 2012
Please give me free quality professional advice so I can be a baby about it and insult you
Did anyone itt ever post about ideas for projects to make or whatever? Because I'm looking through the popular crates on crates.io and trying to come up with simple stuff to make for my Github portfolio. Sorry if this is a dumb question.

Love Stole the Day fucked around with this message at 07:07 on Oct 26, 2017

Workaday Wizard
Oct 23, 2009

by Pragmatica

Hell yeah. This will get rid of a ton of headache.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

Love Stole the Day posted:

What do you guys recommend for GUI crates?
There's not a lot out there, unfortunately. I briefly tried an experiment to see how far I'd get leveraging webrender for the 2d rendering part, but it was such a moving target that I gave up for the time being.

You can still use a binding to QML perhaps (or even to IMGUI if you don't have too many requirements)

comedyblissoption
Mar 15, 2006

Kyren (developer on Starbound) did a cool AMA about making a 2d game in rust:
https://www.reddit.com/r/rust/comments/78bowa/hey_this_is_kyren_from_chucklefish_we_make_and

limaCAT
Dec 22, 2007

il pistone e male
Slippery Tilde
Has anyone installed rust rls successfully in visual studio code and have the project auto compile and run in any debugger (on windows) ? What Rtfm page did I miss?

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
Rust just got some really sweet enum memory layout optimizations. Highlights:
  • ignoring uninhabited variants (i.e. containing uninhabited fields), e.g.:
    • Option<!> is 0 bytes
    • Result<T, !> has the same size as T
  • using arbitrary niches, not just 0, to represent a data-less variant, e.g.:
    • Option<bool>, Option<Option<bool>>, Option<Ordering> are all 1 byte
    • Option<char> is 4 bytes
  • using a range of niches to represent multiple data-less variants, e.g.:
    • enum E { A(bool), B, C, D } is 1 byte

VikingofRock
Aug 24, 2008




Ralith posted:

Rust just got some really sweet enum memory layout optimizations. Highlights:
  • ignoring uninhabited variants (i.e. containing uninhabited fields), e.g.:
    • Option<!> is 0 bytes
    • Result<T, !> has the same size as T
  • using arbitrary niches, not just 0, to represent a data-less variant, e.g.:
    • Option<bool>, Option<Option<bool>>, Option<Ordering> are all 1 byte
    • Option<char> is 4 bytes
  • using a range of niches to represent multiple data-less variants, e.g.:
    • enum E { A(bool), B, C, D } is 1 byte

This is extremely cool!

Beamed
Nov 26, 2010

Then you have a responsibility that no man has ever faced. You have your fear which could become reality, and you have Godzilla, which is reality.


limaCAT posted:

Has anyone installed rust rls successfully in visual studio code and have the project auto compile and run in any debugger (on windows) ? What Rtfm page did I miss?

This is sort of iffy. I feel like everytime I don't use Rust for a couple months and come back to it with VS Code, I have to completely re-set it up from scratch. That and the fact the RLS keeps breaking with nightly's is really frustrating - I'm currently using the JetBrains Rust plug-in to at least more success now.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Yeah the intellij plugin is much better right now. RLS will likely be the superior choice eventually but it’s not there yet.

Adbot
ADBOT LOVES YOU

Beamed
Nov 26, 2010

Then you have a responsibility that no man has ever faced. You have your fear which could become reality, and you have Godzilla, which is reality.


MALE SHOEGAZE posted:

Yeah the intellij plugin is much better right now. RLS will likely be the superior choice eventually but it’s not there yet.

Even that just randomly decides to stop working for even syntax highlighting for me, though. I think I'll go back to Sublime which at least doesn't try for now. :smith:

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