We’ll go into macros in a later post, but know that macros in Rust are so common that 100% of the logic in your first Hello World app will be wrapped up into one. Don’t install cargo-workspace expecting the same functionality. Install cargo-workspaces via $ cargo install cargo-workspaces One of its most valuable features is automating the publish of a workspace’s members, replacing local dependencies with the published versions. It was inspired by node’s lerna and picks up where cargo leaves off. Install cargo-edit via $ cargo install cargo-editĬargo workspaces (or cargo ws) simplifies creating and managing workspaces and their members. If you skimmed the above portion, make sure you don’t miss out on cargo-edit which adds cargo add and cargo rm (among others) to help manage dependencies on the command line. Other-project = Ĭheck cargo-workspaces in the next section for a tool to help manage cargo workspaces. In Rust, you create a Cargo.toml file in the root directory with a entry that describes what’s included and excluded in the workspace. Workspaces & monoreposīoth package managers use a workspace concept to help you work with multiple small modules in a large project. If you do go the Makefile route, check out isaacs’s tutorial and read Your makefiles are wrong. I’ve become skilled writing Makefiles but I wish I spent that time learning just so take a lesson from me and start there. I liked cargo make at first but its builtin tasks became just as annoying as make’s. Other alternatives include cargo-make and cargo-cmd. It irons out a lot of the wonkiness of Makefiles while keeping a similar syntax. Makefiles are still common but just is an attractive option that is gaining adoption. In the Rust ecosystem, you’re not as lucky. Npm’s built-in task runner is one of the reasons why you rarely see Makefiles in JavaScript projects. In Rust you have cargo doc.įor code generation or pre-build steps, cargo supports build scripts which run before the main build.Ī lot of your use cases are covered by default, but for anything else you have to fend for yourself. In node.js you might use npm run docs to generate documentation. In Rust you have cargo clean which will wipe away your build folder ( target, by default). In node.js you might use npm run clean to remove temporary or generated files. In node.js you might use npm run build to run webpack, tsc, or whatever. In node.js you might use npm run benchmarks to profile your code. You can even use cargo run -example xxx to automatically run example code. In node.js you might use npm run start to run your server or executable. In Rust, it depends… You have commands for common tasks but the rest is up to you. You’ll need to have an account on crates.io and set up the authentication details but cargo will help you there. In Rust you have cargo publish.Įasy peasy. There’s a lot to Rust testing that we’ll get to in a later post. In Rust you have cargo test.Ĭargo automates the running of unit tests, integration tests, and document tests through the cargo test command. You don’t need to sudo cargo install anything. If you installed rust via rustup then these are placed in a local user directory (usually ~/.cargo/bin). In Rust you have cargo install.ĭownloading, building, and placing executables in cargo’s bin directory is handled with cargo install. This gives you four new commands: add, rm, upgrade, and set-version Installing tools globally Note: not cargo-add, just in case you come across it. In Rust you can use cargo add if you install cargo-edit first. cargo new initializes projects in a new directory. In Rust you have cargo init and cargo new.Ĭargo init will initialize the current directory. Cargo uses the Cargo.toml file to know what dependencies to download, how to run tests, and how to build your projects ( among other things). In Rust you have Cargo.toml.Ĭargo’s manifest format is toml rather than the JSON you’re used to with npm’s package.json. Npm to cargo mapping Project settings file ![]() Day 21: Building and Running WebAssembly.Day 16: Lifetimes, references, and 'static.Day 9: Language Part 3: Class Methods for Rust Structs (+ enums!).Day 8: Language Part 2: From objects and classes to HashMaps and structs.Day 4: Hello World (and your first two WTFs).Post questions and comments to me on Twitter or and join others taking this same plunge on our Discord channel. When something is glossed over, we’ll add links for those looking to dive deeper. ![]() This guide tries to balance technical accuracy with readability and errs on the side of “gets the point across” vs being 100% correct. We’ll take common node.js workflows and idiomatic JavaScript and TypeScript and map them to their Rust counterparts. ![]() It’s meant to bootstrap experienced node.js users into Rust. This guide is not a comprehensive Rust tutorial.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |