Rust on Particle: development discussion


#21

That’s perfect, just making sure were aware, didn’t want you to be left out :smile:

I guess I should say, of those who have spoken up, that seems to be the consensus. Don’t mean to speak for those have not.

It is still very nascent, it seems like most of the effort is in getting Cargo to work. But there is quite a lot to do and probably even more to discuss in order to work out the details. I’d say pick one of those issues that interests you and start looking into it, ask questions and start dialogue.

Personally, I’ve found This Week in Rust to be a good resource for getting up to speed on the state of rust as well as some projects that people are working on that can help you learn rust. Also, I’ve been watching this series on Youtube about building an N64 emulator in Rust, that’s been really fun and super informative.


#22

Nice! I’ll definitely check those out. Cargo is definitely one of my favourite aspects of the language and supporting frameworks, so I’ll likely start there as well.

As for information, http://www.newrustacean.com has been pretty awesome for getting a conceptual overview of the language; It’s just a bunch of podcasts by a guy (Chris Krycho) who’s making them as he learns the language.

I think my biggest sticking point right now, is how to make effective use of Traits… still haven’t had my eureka-moment with those.


#23

Yeah, I know what you mean lol


#24

Rust 1.7: http://blog.rust-lang.org/2016/03/02/Rust-1.7.html


#25

Cool idea here! I’ve been itching to get into rust, but haven’t found a good project yet. So please take my contribution here with a grain of salt-of-inexperience

Edit: I see the same principle was already suggested on the github issue:

Regarding Zach’s ideas:

From my rust-research so far, the idiomatic way to do this seems to be to use lifetimes and ownership.
The entire “pinmode” hassle is conceptually orthogonal because it’s global mutable state.

The rust-way as I understand it so far would have a “guard object” claim ownership of and wrap around the contended resource. My inspiration here is a variable wrapped by a Mutex lock.
The variable inside is only reachable via mutex.acquire(), and as long as that borrow’d result is in scope, other acquires are impossible.

We’d need marker Traits (similar to Send, Sized, Sync, etc) for DigitalInputPin, DigitalOutputPin, AnalogInputPin, PwmPin, etc.

Suggestion in pseudo code typed on a phone keyboard(sorry in advance for any typo’s):

board.rs:

struct D7 {};
struct A0 {};

impl DigitalInputPin for D7;
Impl DigitalOutputPin for D7;
Impl AnalogOutputPin for A0;

MyProgram.rs

{
let outputPin = IO::digitalOut(board::D7);  // claims ownership of D7 marker struct, preventing repeated init
outputPin.setHigh(); // statically guaranteed to work, because setHigh method is only available on correct guard object
outputPin.setLow();

// compile error: D7 no longer owned here:
let failedAttempt = IO::digitalIn(D7);
// compile error: D7 doesn't impl AnalogInputPin
let anotherFailedAttempt = IO::analogOutputPulldown(D7);
} // output pin leaves scope, implicit release of D7
{
let secondTry = IO::digitalIn(board::D7);
let pinValue : bool = secondTry.read(); // maybe "pinvalue : IO:pinOutput" enumtype?
}

By only impl’ing the modes a given pin supports, you statically prevent setting a pin to the wrong pinmode, anything else would trigger type-errors on the function call to init the guard.


#26

Any news on the Rust front?


#27

The latest and greatest can be found here: https://github.com/japaric/photon


#28

(Sorry to resurrect this old topic. It does seem like the best place to ask, however.)

Is Rust still a thing that Particle is supporting or plans to support? I want to learn Rust, and I need a project; my current efforts on Particle stuff at work is a great opportunity for this, and I don’t know if it’s still an option or not. The mainline firmware seems to keep maturing, and I don’t see anything on the Rust branch. Even the repo that @zach linked in above hasn’t been updated in 10 months.

Thanks.

Again, sorry for the resurrection.


#29

I always planned to start working on this, but can’t find time for it :frowning2:


#30

reality comes for us all.


#31

Same; I am not a proficient enough Rust engineer to be able to work on it meaningfully myself, but my hope is to be the sponsor of such a project. My attention has been drawn elsewhere for the last couple of months but I do plan to hop back on this at some point in the next couple of months.


#32

The latest and greatest can be found here: https://github.com/japaric/photon

I have restarted development of that repository but the getting started guide is now here. I made a new thread with more details about my recent work; check it out.