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
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

gonadic io posted:

Is there a way to generate an identifier inside a macro?
Given that rust macros are intended to be hygenic, what happens if you just give the struct a fixed identifier directly? If it works at all I imagine it'll be scoped to the macroexpansion.

Adbot
ADBOT LOVES YOU

gonadic io
Feb 16, 2011

>>=

Ralith posted:

Given that rust macros are intended to be hygenic, what happens if you just give the struct a fixed identifier directly? If it works at all I imagine it'll be scoped to the macroexpansion.

That worked perfectly actually, thanks. Also because the struct is created inside the macro body expression anyway:
code:
let mut digit = unsafe {
    create_eight_segment!(D7, D6, D3, D4, D5, D8, D9, D2)
  };
There's no way for the scope to clash at all. Thanks to macros I can even name those arguments like "PIN_1 = D7" in a way that I couldn't with regular functions!

edit: is it best practice to have the expansion be
code:
let mut digit = unsafe {
    struct Foo;
    impl Butt for Foo {}
    Foo::new()
  }
I'm still not sure how this would affect how that block actually executes at run-time. Would all the type definitions and impls happen at compile-time so at run-time that's identical to just having the "Foo::new()" on its own?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Aren't Rust's macro's hygienic? Maybe I'm missing the point, sorry.

E: new page, whoops

Mr. Glass
May 1, 2009

gonadic io posted:

I'm still not sure how this would affect how that block actually executes at run-time. Would all the type definitions and impls happen at compile-time so at run-time that's identical to just having the "Foo::new()" on its own?

everything type related (as i understand it, in Rust) is static, i.e., at compile time. the compiler can prove that Foo implements Butt, but there's no way for you to refer to Foo anywhere outside of the macro rule (despite the fact that it's possible to interact with values of that type).

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

gonadic io posted:

I'm still not sure how this would affect how that block actually executes at run-time. Would all the type definitions and impls happen at compile-time so at run-time that's identical to just having the "Foo::new()" on its own?
As Mr. Glass says, placing type shenanigans inside blocks like that is purely a matter of name visibility. Rust has no notion of run-time definition of new types or trait impls.

gonadic io
Feb 16, 2011

>>=
That's absolutely perfect then, entirely what I want. Now I just need to decide is this is a good idea or not:

gonadic io
Feb 16, 2011

>>=
Or even better I could make a macro that's invoked like:
code:
let zero = eight_segment_digit!(
  _ 
 | | 
 |_|
);
let two_point = eight_segment_digit!(
  _
  _|
 |_ o
);
:q:

gonadic io fucked around with this message at 00:16 on Mar 23, 2017

VikingofRock
Aug 24, 2008




gonadic io posted:

Or even better I could make a macro that's invoked like:
code:
let zero = eight_segment_digit!(
  _ 
 | | 
 |_|
);
let two_point = eight_segment_digit!(
  _
  _|
 |_ o
);
:q:

Definitely do this, then post it here. This sounds awesome.

taqueso
Mar 8, 2004


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

:pirate::hf::tinfoil:

gonadic io posted:

Or even better I could make a macro that's invoked like:
code:
let zero = eight_segment_digit!(
  _ 
 | | 
 |_|
);
let two_point = eight_segment_digit!(
  _
  _|
 |_ o
);
:q:

Awhile back I made a thing to allow binary literals to be entered as XX_XXX_XX to allow 'drawing' sprites for a Chip8 emulator. You need to use a compiler plugin rather than a macro to do that kind of stuff.

Here is the response to my post: https://forums.somethingawful.com/showthread.php?threadid=3694683&pagenumber=6&perpage=40#post461902966

gonadic io
Feb 16, 2011

>>=

gonadic io posted:

Got my Arduino's ADC working in Rust! i'm p happy not going to lie

code:
const VAR_RES: Port = A2;
const ADC: *mut ADC = 0x42004000 as *mut ADC;

pub fn main() {
    unsafe {
        VAR_RES.set_pin_dir(false);
        let mut digit = create_eight_segment!(D7, D6, D3, D4, D5, D8, D9, D2);

        loop {
            let s = (*ADC).analog_read(VAR_RES) as u32;        
            digit.display( s >> 7 );
            delay(100);
        }
    }
}
https://www.youtube.com/watch?v=rE2VUSBSRB8

Now to give it a decent and safe interface as opposed to casting a u32 constant to a memory address to a pointer to a struct :q:.

gonadic io fucked around with this message at 14:07 on Apr 4, 2017

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.

Workaday Wizard
Oct 23, 2009

by Pragmatica

Asymmetrikon posted:

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.

I didn't do anything special.

Try building your project.

ssergE
Sep 10, 2001

No longer a stupid baby. Now a stupid teenager.

Asymmetrikon posted:

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.

Is this if you do the "New Project" dialog in IDEA? If so, I had the same issue but found I could leave it blank and it sorted itself out automatically upon doing the initial indexing.

Here's a problem I've having at the moment with the plugin: How do I get IDEA to run the Visual Studio 2017 command prompt environment (vcvars64) to allow cargo to work properly (requires link.exe)?

EDIT: Apparently it's a known issue with VS2017 and rustup/cargo.
https://github.com/rust-lang/rust/issues/38584
https://github.com/rust-lang-nursery/rustup.rs/issues/1003

ssergE fucked around with this message at 02:45 on Apr 25, 2017

Workaday Wizard
Oct 23, 2009

by Pragmatica

ssergE posted:

Is this if you do the "New Project" dialog in IDEA? If so, I had the same issue but found I could leave it blank and it sorted itself out automatically upon doing the initial indexing.

Here's a problem I've having at the moment with the plugin: How do I get IDEA to run the Visual Studio 2017 command prompt environment (vcvars64) to allow cargo to work properly (requires link.exe)?

EDIT: Apparently it's a known issue with VS2017 and rustup/cargo.
https://github.com/rust-lang/rust/issues/38584
https://github.com/rust-lang-nursery/rustup.rs/issues/1003

I ran "Developer Command Prompt for VS 2017", dumped the variables with "set > env_file", then added the variables to my running configuration (.idea/workspace.xml).
This way I was able to build and run directly from Intellij.

gonadic io
Feb 16, 2011

>>=
If anybody was interested in my arduino rust project, there's a new amazing guide on the best toola/libraries to use for it: http://blog.japaric.io/quickstart/

I'm busy rewriting all of my manual cludges to use this stuff.

Linear Zoetrope
Nov 28, 2011

A hero must cook
So what's been going on in Rust-land in the last bit? Any major changes or features? I've been stuck in Python-land for research aside from some graphics projects with gfx and I'm wanting to get back into some Rust stuff.

QuietMisdreavus
May 12, 2013

I'm fine. Nothing to worry about.

Linear Zoetrope posted:

So what's been going on in Rust-land in the last bit? Any major changes or features? I've been stuck in Python-land for research aside from some graphics projects with gfx and I'm wanting to get back into some Rust stuff.

How long have you been out? Here's the full list of changes by version, but picking some highlights from the last several versions:

gonadic io
Feb 16, 2011

>>=

QuietMisdreavus posted:

How long have you been out? Here's the full list of changes by version, but picking some highlights from the last several versions:


I think impl trait is my favourite of the new features, just because it makes working with unboxed closures and iterators so much easier.

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

gonadic io posted:

I think impl trait is my favourite of the new features, just because it makes working with unboxed closures and iterators so much easier.
I don't think that's stable yet. Is it close?

gonadic io
Feb 16, 2011

>>=

Ralith posted:

I don't think that's stable yet. Is it close?

Not at all. There's still implementation bugs and lots of open design questions. However my Rust is entirely playing around with hobby projects, so I am fine with always using nightly.

Karate Bastard
Jul 31, 2007

Soiled Meat
What is Rust is it some sort of Scientology? I dip into this thread every so often and I never seem to know half the terms you people fling about, and probably the other half don't mean what I think īt do. Is there some sort of indoctrination course you have to take?

taqueso
Mar 8, 2004


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

:pirate::hf::tinfoil:

Yes, it is Scientology, but you aren't invited. Sorry. Not sorry.

TheCog
Jul 30, 2012

I AM ZEPA AND I CLAIM THESE LANDS BY RIGHT OF CONQUEST
I keep meaning to poke at rust but I don't have a good idea of what kinds of projects its well suited to. I've mostly only done webapps and web design like things, (ok and some automation scripts), are there any cool ideas for projects to build? I followed the tutorial in the docs a while back and built the guess checker, but that didn't really give me a good idea of what kinds of cool projects rust enables. Are there any really recommended tutorials or even just suggestions for things to build that people could recommend?

Arcsech
Aug 5, 2008

TheCog posted:

I keep meaning to poke at rust but I don't have a good idea of what kinds of projects its well suited to. I've mostly only done webapps and web design like things, (ok and some automation scripts), are there any cool ideas for projects to build? I followed the tutorial in the docs a while back and built the guess checker, but that didn't really give me a good idea of what kinds of cool projects rust enables. Are there any really recommended tutorials or even just suggestions for things to build that people could recommend?

I built a packet parser (sort of tcpdump-ultralite with some extra mashing for couple particular types of packets) and I thought it worked fantastically well for that. It would also be good for the Matasano crypto challenges.

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

TheCog posted:

I keep meaning to poke at rust but I don't have a good idea of what kinds of projects its well suited to. I've mostly only done webapps and web design like things, (ok and some automation scripts), are there any cool ideas for projects to build? I followed the tutorial in the docs a while back and built the guess checker, but that didn't really give me a good idea of what kinds of cool projects rust enables. Are there any really recommended tutorials or even just suggestions for things to build that people could recommend?
Build a raytracer! Raytracers are always fun and rust won't stop you from making it super fast.

QuietMisdreavus
May 12, 2013

I'm fine. Nothing to worry about.

TheCog posted:

I keep meaning to poke at rust but I don't have a good idea of what kinds of projects its well suited to. I've mostly only done webapps and web design like things, (ok and some automation scripts), are there any cool ideas for projects to build? I followed the tutorial in the docs a while back and built the guess checker, but that didn't really give me a good idea of what kinds of cool projects rust enables. Are there any really recommended tutorials or even just suggestions for things to build that people could recommend?

Rust is built to fill the same niche as C/C++, in a sense. It lets you concern yourself with memory allocation, cache invalidation, and other kinds of hardware-informed optimizations. On the other hand, it's also designed in such a way that you don't have to deal with those concerns if you don't want to. Heck, my first big project was a twitter library, and that fucker is terrible with memory, compared to what I'd consider "optimal". I think if you're looking to make some kind of web API, or other kind of web facing thing, there's been a lot of work in that area that will make things really easy. (Rocket is really slick, if you haven't seen that one yet.) Other areas are more lacking, like GUI design, or database integration. There are means to do both of those things, but I don't think they've been polished to the point where they're easy to do in Rust.

xtal
Jan 9, 2011

by Fluffdaddy
I made a web app with Rocket and tbh it almost put me off Rust entirely. Probably 90% of it happens in macros, and Rust has one of the worst macro systems ever. Rust is going to need to address this at some point because the rigidity of the language makes you use macros and macros are worthless without homoiconicity

JawnV6
Jul 4, 2004

So hot ...

QuietMisdreavus posted:

It lets you concern yourself with ... cache invalidation

How's it do that?

TheCog
Jul 30, 2012

I AM ZEPA AND I CLAIM THESE LANDS BY RIGHT OF CONQUEST
Thanks for all the suggestions and advice. I think I'm going to kick off with the easier cryptochallenges, and then maybe try my hand at a raytracer. I've never built anything like that before so it should be a fun challenge. I'll also poke at Rocket, although I honestly have enough ways to code web stuff, i'm always interested in seeing new implementations.

QuietMisdreavus
May 12, 2013

I'm fine. Nothing to worry about.

JawnV6 posted:

How's it do that?

"Providing separate Vec and LinkedList types" was the main thing i had in mind. Maybe the other major thing i was thinking of was "a distinction between stack and heap", since that's easier to see.

Karate Bastard
Jul 31, 2007

Soiled Meat

taqueso posted:

Yes, it is Scientology, but you aren't invited. Sorry. Not sorry.

That doesn't sound much like Scientology at all!

But joking aside, is there such a thing nowadays similar to that go tutorial? That was super efficient in getting me into go, to understanding the key points that set it apart from other languages I knew from previous and how to think about it.

Rust didn't have that in the past (afaik?) so I'm still an ignoramus. Does it now?

Workaday Wizard
Oct 23, 2009

by Pragmatica

Karate Bastard posted:

That doesn't sound much like Scientology at all!

But joking aside, is there such a thing nowadays similar to that go tutorial? That was super efficient in getting me into go, to understanding the key points that set it apart from other languages I knew from previous and how to think about it.

Rust didn't have that in the past (afaik?) so I'm still an ignoramus. Does it now?

The book is nice (check out the second edition first): https://doc.rust-lang.org/book/
There is also Rust by Example which is useful: https://rustbyexample.com/
Additionally you might find this guide useful later after you get the basics: https://github.com/kmcallister/rustic-symmetries

e:
The docs are quite useful and contain a lot of examples: https://doc.rust-lang.org/std/
PS: You can view the actual code from the documentation pages by clicking [src] at the top.

e2:
Don't forget to check out the super friendly user forum: https://users.rust-lang.org/ and IRC: #rust-beginners @ irc.mozilla.org

Workaday Wizard fucked around with this message at 15:25 on Jun 30, 2017

Karate Bastard
Jul 31, 2007

Soiled Meat
Hey neat, thanks!

QuietMisdreavus
May 12, 2013

I'm fine. Nothing to worry about.
To add onto the resource pile, Rustlings is a really great set of small exercises that echoes the (first edition) book in terms of what it introduces when. Plus it leans on the playground, which is a truly fantastic resource to get your feet wet with Rust without having to install anything.

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

xtal posted:

I made a web app with Rocket and tbh it almost put me off Rust entirely. Probably 90% of it happens in macros, and Rust has one of the worst macro systems ever. Rust is going to need to address this at some point because the rigidity of the language makes you use macros and macros are worthless without homoiconicity
I don't have any experience with Rocket, but I hardly ever find myself reaching for macros when writing Rust. First-class functions, closures, traits, and polymorphism go a long way. Which is good, because macros 1.0 really do suck for any but the most trivial uses. Custom derive (stable, demonstrated nicely by serde) and the upcoming macros 2.0 (which gives you full-powered source-to-source transforms) are a lot nicer, fortunately.

gonadic io
Feb 16, 2011

>>=

Ralith posted:

I don't have any experience with Rocket, but I hardly ever find myself reaching for macros when writing Rust. First-class functions, closures, traits, and polymorphism go a long way. Which is good, because macros 1.0 really do suck for any but the most trivial uses. Custom derive (stable, demonstrated nicely by serde) and the upcoming macros 2.0 (which gives you full-powered source-to-source transforms) are a lot nicer, fortunately.

The only things that I define my own macros for are 1) early returns, like:
code:
macro_rules! try_opt(
    ($e:expr) => (match $e { Some(e) => e, None => return None })
);

macro_rules! guard(
    ($e:expr) => (if !$e { return None })
);
or 2) saving boilerplate (or abstracting in consts) like
code:
macro_rules! vert (($p:expr, $t:expr) => (
    Vertex {
        pos: [$p[0] as f32, $p[1] as f32, $p[2] as f32],
        tex_coord: [$t[0] as f32, $t[1] as f32],
    }
));
and even then 1) will go away when "try" is extended into a trait, and 2) will go away with better const fns. The only other thing that I'd write my own stuff for are when I have varargs or really want to template a function in a way that the type system can't express.

gonadic io fucked around with this message at 23:38 on Jul 2, 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
I want to be able to build EDSLs. My day job is C++ so I'm not exactly chafing at Rust's lack of expressiveness, but it'll be a good day when the next iteration is stabilized.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
I really like rust and I can't wait for it to become employable so I can get a job writing it.

xtal
Jan 9, 2011

by Fluffdaddy
Just get a job writing C and use extern no_mangle

Adbot
ADBOT LOVES YOU

QuietMisdreavus
May 12, 2013

I'm fine. Nothing to worry about.
Technically there's https://rustjobs.rs/, but it's fairly light (apparently they went and scrubbed all the ones that have been filled since the last time i looked).

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