9 ms·
First steps with Rust
- lorenzfx 6y agoI find the fact that MS is promoting Rust in itself much more interesting than the content. Also, I would still really like to learn Rust properly, but I don't have any use for it currently either at my day job nor for my side projects.
- austincheney 6y agoI have a file system distribution application I am working on. It is written entirely in TypeScript but I envision using Rust to perform certain media execution tasks or things heavily focused upon arithmetic like financial data analysis. My application is fully isomorphic so the only value in TypeScript on the terminal is for portability of systems automation with Node. Tasks that do not require cross-OS systems portability can be done with something like Rust as a child process.
- brundolf 6y agoFwiw Rust has fantastic cross-OS systems portability in just about every way except the fact that you have to compile separately for each platform (which you obviously don't for Node). But if you aren't needing to ship a single precompiled binary, you should have no problems.
- alain_gilbert 6y agoIf you are interested in rust and want a very simple project to try it on: I made a bot library for https://turntable.fm/ https://turntable.fm/ in javascript -> https://github.com/alaingilbert/Turntable-API https://github.com/alaingilbert/Turntable-API Then I rebuilt it in go -> https://github.com/alaingilbert/ttapi https://github.com/alaingilbert/ttapi Then I tried to write it in rust, but the pattern isn't really good with the borrow checker, I cannot make this work -> https://github.com/alaingilbert/rust-ttapi/blob/47282b7a334d947ccc38cf7e9179fae2cb632b96/src/main.rs#L342 https://github.com/alaingilbert/rust-ttapi/blob/47282b7a334d... So if someone can find a good pattern to use for this type of library, I would gladly want to learn. Pull requests are welcome, I'm also always on discord if you want to chat.
- rav 6y agoYou cannot access "bot" inside bot.on_speak(|| { ... }) because Rust does not know that the "bot" variable stays alive for whenever the callback is called. In this situation I would expect "bot" to be stored in an Arc, and then you would move a clone of the Arc into the callback: let bot = Arc::new(bot); bot.on_speak({ let bot = bot.clone(); move |evt: SpeakEvt| { ... }}); Edit to add: Alternatively, the bot could pass a mutable reference to itself to the callback when it is invoked. bot.on_speak(|bot, evt: SpeakEvt| { ... })
- alain_gilbert 6y agoeasier said than done though. I tried the second option (calling callback with a mut reference to self) but I couldn't make it all work. I think I also had issues with "async" in a closure that could not be done. Anyway, if you can make it work, I'll study your code religiously !
- masklinn 6y ago> I think I also had issues with "async" in a closure that could not be done. Yes, async closures are not currently stable, which is a huge pain in the ass: you have to use a regular closure with an `async` block inside, but said async block will usually need to be an `async move` block, which requires more contorsions because you can't just use stuff the closure owns as that'd make said closure FnOnce (the closure's item is moved into the `async move` block meaning the closure is destroyed). This is usually solved by putting the item behind an `Arc` (if it's too costly to be directly copied, or if you want / need to mutate it), this way you can `clone()` the arc so the async move block has its own "copy". Alternatively, have the closure immediately and only call into an async function or method. I can't wait for async closures, though, I'm sure others have their own bugbears but that's by far my biggest pain in the ass when using async rust.
- rav 5y agoHere you go: https://github.com/alaingilbert/rust-ttapi/pull/1 https://github.com/alaingilbert/rust-ttapi/pull/1
- mikepurvis 6y agoI did advent of code in it this past year as a learning exercise and had a great time. It’s not exactly “real world”, but it’s great for soaking up syntax, algorithms, many basic crates, etc, without locking a project into a bunch of bad design decisions.
- geodel 6y agoMicrosoft is promoting / providing courses on all sort of languages and technologies and so are other cloud providers. It is good to know but it sure is not like "Rust on Microsoft site? This changes everything!!" E.g. here are course for Go [1], for Java[2] 1. https://docs.microsoft.com/en-us/learn/paths/go-first-steps/ https://docs.microsoft.com/en-us/learn/paths/go-first-steps/ 2. https://docs.microsoft.com/en-us/learn/paths/java-on-azure/ https://docs.microsoft.com/en-us/learn/paths/java-on-azure/
- staticassertion 6y agoYeah we get it you don't like rust.
- 6c696e7578 6y agoMicrosoft don't sell software in this context. They're selling a service, primarily Azure. Azure is the mainframe that you'll be running your Rust applications on and paying Microsoft the monthly rental for that. Microsoft don't care if that is a Rust, Java, Python, Visual Basic or PowerShell application. They only care that you choose to do it in Azure (so lets learn the Microsoft centric ways early) though.
- harikb 6y agoLooking at the contents, it doesn’t seem like they are pitching Azure specifically. The Java one shown in a sibling comment does talk about Azure API. At least the work done by MS on VsCode, Language Server, TypeScript etc is truly helping whole community. May be there is something in Rust world as well.
- ModernMech 6y agoStep 4 of this tutorial is "Install Visual Studio Code", so Microsoft is definitely using this as a vehicle to promote VSC.
- watermelon0 6y agoI don't think vscode needs any additional promotion.
- ModernMech 6y agoSure it does. I teach intro programming and I have 100+ freshmen students every semester who have no idea what visual studio code is. Students in US high school are learning Java these days due to it being the language of the AP exam, and they're not using Visual Studio or VSC. They're using IntelliJ, Netbeans, and Eclipse. Microsoft needs these kids to use VSC to get them on the Microsoft developer path early.
- steveklabnik 6y agoVS: Code has already been in first or very close to it inside the Rust community for years now. VS: Code doesn't put you down a particular "Microsoft developer path" at all.
- ModernMech 6y ago> VS: Code has already been in first or very close to it inside the Rust community for years now. True, but the directions to VSC in this case don't seem to relate to that, as these tutorials do the same for Go and Python. It's part of the strategy of this site. They want you to learn Python with VSC, and Go with VSC, not because they want you to learn Python or Go, but because they want you to use a Microsoft property in the process. Just as they aren't teaching you Git through this site, they are teaching you Git in the context of Github. All arrows are pointing toward Microsoft properties. I'm not saying this is a bad thing or wrong, but people here are asking "What's the catch" and it's all just marketing. > VS: Code doesn't put you down a particular "Microsoft developer path" at all. I disagree. Like I said, students emerging from high school are fully steeped in the Java ecosystem. A lot of them think that programming == Java. Many don't even have a concept that there is more than one programming language out there, and don't see a purpose of anything other than Java. The best thing MS can do to get people into .Net land is to get them out of JVM land. VSC is that vehicle. It doesn't matter what language they're using as long as they're using it in a Microsoft branded context. Not to mention half the people (I'm exaggerating of course) who set out to install VSC end up installing Visual Studio Community. I don't think that's intentional on Microsoft's part, but I'm sure they aren't mad at it.
- brundolf 6y agoFun Rust projects I've done that it was well-suited to: - Conway's Game of Life - Graphics stuff (raytracing, procedural generation, etc) - Parsers/interpreters/compilers - Command-line tools None of these were things I needed exactly, but that's the fun of side projects :)
- vander_elst 6y agoWhat's the strategy behind this move? Is MS adding some Rust APIs to some of their products?
- pca006132 6y agohttps://cloudblogs.microsoft.com/opensource/2021/02/08/microsoft-joins-rust-foundation/ https://cloudblogs.microsoft.com/opensource/2021/02/08/micro... They are one of the founding member of Rust Foundation, and from the article it seems that they do use Rust in some of their products.
- yannikyeo 6y agoThey released a while back Rust crate for Windows API: https://github.com/microsoft/windows-rs https://github.com/microsoft/windows-rs
- toyg 6y agoI wouldn’t be surprised to learn that MS see Rust as a strategic “safer C” going forward. They have tons of legacy, dangerous C/C++ code across their traditional products (and Windows in particular), which could be slowly replaced with more robust Rust implementations.
- dsfbjornjaja 6y agoUntil Rust is replaced with something else (perhaps steel-lang or carbon-nanotube-lang). :)
- wongarsu 6y agoRust also fits perfectly into their general desire for robust drivers, for example with the Static Driver Verifier [1]. If a device driver misbehaves people usually blame Windows, so they spend energy on reducing the classes of bugs that can happen. 1: https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/survey-of-verification-tools https://docs.microsoft.com/en-us/windows-hardware/drivers/de...
- iudqnolq 6y agoMicrosoft's c codebase is heavily annotated with custom annotations they check at compile time. It's not as powerful as Rust, but very cool. https://docs.microsoft.com/en-us/cpp/code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects?view=msvc-160 https://docs.microsoft.com/en-us/cpp/code-quality/using-sal-...
- adenozine 6y agoWhen will there be another implementation of Rust? If there's ever a GNU implementation, I might be willing to try it.
- geofft 6y agohttps://github.com/Rust-GCC/gccrs https://github.com/Rust-GCC/gccrs is in progress, but I believe it works enough to be worth playing with. Note that it doesn't implement the borrow checker - the plan is to reuse rustc's borrow checker as a compiler plugin. For now, as I understand it, gccrs itself assumes that the code is valid (i.e., would be accepted by rustc). https://thephilbert.io/ https://thephilbert.io/ is the primary developer's blog and has status updates.
- nextaccountic 6y agoSome links on the most promising effort so far, gccrs https://opensrcsec.com/open_source_security_announces_rust_gcc_funding https://opensrcsec.com/open_source_security_announces_rust_g... https://www.embecosm.com/2021/01/12/gcc-rust-how-it-can-be-achieved/ https://www.embecosm.com/2021/01/12/gcc-rust-how-it-can-be-a... https://rust-gcc.github.io/ https://rust-gcc.github.io/ This is an entirely new frontend written in C++, that shares no code with rustc (the official rust compiler). It might be merged some day in GCC proper. But honestly, I'm more excited for rustc_codegen_gcc: https://github.com/antoyo/rustc_codegen_gcc https://github.com/antoyo/rustc_codegen_gcc It adds gcc as an alternative backend of the official Rust compiler. That way it is much more feasible to stay up to date as the language evolves. Anyway the former two don't actually work right now. The one that does work today is mrustc, or at least it works for bootstrapping rustc; it doesn't have a borrow checker though (and instead assumes the program is correct). Also, mrustc isn't based on gcc. https://github.com/thepowersgang/mrustc https://github.com/thepowersgang/mrustc (There's a fourth project, https://github.com/sapir/gcc-rust https://github.com/sapir/gcc-rust, but it seems abandoned)
- dhosek 6y agoMeh. Part of what makes rust appealing over C++ for my current project is that the latter has at least three major target compilers with subtle differences in how they implement things that mean that even staying within the bounds of the standard might result in different outcomes in the code (not to mention the whole mess around dependencies in C++ code). Multiple implementations of a language feels more like a bug than a feature to me.
- lodovic 6y agoThis looks like a nice addition to the Rust cookbook. It seems a bit more structured, and I actually like that it gives XP for completing the chapters.
- loloquwowndueo 6y agoMicrosoft promoting rust, never thought I’d live to see the day. Not clear why one would choose this over the official rust documentation and tutorials. Oh and also - it’s a trap. Microsoft are not friends of free software.
- koheripbal 6y agoHow is it a trap? Please don't make vague accusations. If you have something substantive to add - describe it.
- loloquwowndueo 6y agoOh vague? You mean like calling open-source software a "cancer" and "an intellectual-property destroyer” ? https://www.cnet.com/news/microsoft-red-hat-argue-open-source/ https://www.cnet.com/news/microsoft-red-hat-argue-open-sourc...
- ulimn 6y agoI think what they meant by "vague" is that you did not tell us why you think it was a trap. :)
- flohofwoe 6y agoCan you show some evidence that's less than two decades old though? ;) Open source has "won" in the meantime. Why would Microsoft be interested in turning back the clock now that the money is in services, no longer in software.
- littlestymaar 6y agoThe most interesting thing here is that this tutorial has been translated to around 50 languages! Rust tutorials and documentation are abundant in English, but the resource is much scarcer in most people's native language.
- Klwohu 6y agoMS is stepping up and becoming the only real large Rust patron. It'll be interesting to see where Microsoft takes this newish language. My question is, will the Rust evangelists act even more like Windows shills than they already are?
- shimonabi 6y agoNeeds some proofreading: "Until then, you can think of String data as string data that can change as your program runs, while &str are immutable views into string data that do not CHANGES as your program runs." // Instantiate a tuple struct by passing the values in the same order as defined. let origin = Point2D(0, 0) // Missing ;
- robrorcroptrer 6y agoDo they ever debug the application inside VSCode in this tutorial?
- mrlonglong 5y agoI'm greatly encouraged to try out Rust with Linux. I do wonder if I can do an out of tree kernel module to make my life easier developing. I know I could do this with ordinary kernel modules.
- mrlonglong 5y agoTo add to this, I did some browsing and found this: https://GitHub.com/tsgates/rust.ko https://GitHub.com/tsgates/rust.ko