{"id":21068779,"url":"https://github.com/dev-cafe/rust-demo","last_synced_at":"2025-05-16T03:33:35.921Z","repository":{"id":37101842,"uuid":"232095683","full_name":"dev-cafe/rust-demo","owner":"dev-cafe","description":"Hands-on demo of the Rust programming language.","archived":false,"fork":false,"pushed_at":"2022-06-17T06:35:33.000Z","size":686,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-01-29T08:48:12.204Z","etag":null,"topics":["fortran","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dev-cafe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-06T12:24:57.000Z","updated_at":"2023-08-24T20:39:44.000Z","dependencies_parsed_at":"2022-06-24T08:22:53.641Z","dependency_job_id":null,"html_url":"https://github.com/dev-cafe/rust-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-cafe%2Frust-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-cafe%2Frust-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-cafe%2Frust-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-cafe%2Frust-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dev-cafe","download_url":"https://codeload.github.com/dev-cafe/rust-demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225404421,"owners_count":17469141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fortran","rust"],"created_at":"2024-11-19T18:25:23.025Z","updated_at":"2024-11-19T18:25:23.712Z","avatar_url":"https://github.com/dev-cafe.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# rust-demo\n\nHands-on demo of the Rust programming language.\n\n\n## History of Rust\n\n- Originally designed by Graydon Hoare at Mozilla Research, with contributions from Dave Herman, Brendan Eich, and others.\n- Mozilla began sponsoring the project in 2009.\n- Announced 2010: http://venge.net/graydon/talks/intro-talk-2.pdf\n- Rust 1.0, the first stable release, released in 2015.\n- Since 2011 `rustc` is compiled using `rustc`.\n- `rustc` uses LLVM as its back end.\n- The History of Rust: https://www.youtube.com/watch?v=79PSagCD_AY\n- Firefox (components Servo and Quantum) written in Rust.\n- Ad block engine in [Brave](https://brave.com/).\n- `exa`, `ripgrep`, `bat`, and `fd` written in Rust (you really want these tools!).\n- Great overview of tools written in Rust: https://www.wezm.net/v2/posts/2020/100-rust-binaries/\n- [Discord](https://discord.com/) uses Rust for some of its backed.\n\n\n## Why Rust\n\n- \"A language empowering everyone to build reliable and efficient software.\" (https://www.rust-lang.org)\n- Fast but also safe\n- Zero cost abstractions\n- Type system\n- Compiler catches most errors (if it compiles, it often just works)\n- Compiler provides helpful error messages\n- Memory safety\n- Thread safety\n- Private and immutable by default\n- Great tooling (testing, documentation, auto-formatter, dependency management, package registry, no makefiles needed)\n- Community\n- Most-loved programming language in the 2016, 2017, 2018, 2019, and 2020\n  [Stack Overflow annual surveys](https://insights.stackoverflow.com/survey/)\n\n\n## Great resources\n\n- [Rust by Example](https://doc.rust-lang.org/rust-by-example/)\n- [The Rust Programming Language](https://doc.rust-lang.org/book/)\n- [The Rustonomicon](https://doc.rust-lang.org/nomicon/)\n- [Rust Cookbook](https://rust-lang-nursery.github.io/rust-cookbook/)\n- [Why try Rust for scientific computing?](https://erambler.co.uk/blog/why-give-rust-a-try/)\n- [Rust in Action](http://www.rustinaction.com/)\n- [The Rust FFI Omnibus](http://jakegoulding.com/rust-ffi-omnibus/)\n\n\n## Memory model\n\n- No explicit allocation and deallocation.\n- No garbage collector either.\n- Each value in Rust has an owner and there can only be one owner at a time.\n- When the owner goes out of scope, the value is dropped.\n- Rust knows the size of all stack allocations at compile time.\n\nThis does not compile:\n```rust\nlet s1 = String::from(\"hello\");\nlet s2 = s1;\n\nprintln!(\"{}, world!\", s1);\n```\n\n- Rust's memory is managed a bit like money: one owner, it can be borrowed.\n- We can borrow references: https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#references-and-borrowing\n- At any given time, you can have either one mutable reference or any number of immutable references.\n\n\n## Installing Rust\n\nPreferred way to install Rust for most developers: https://www.rust-lang.org/tools/install\n\nVerify your installations of `cargo` and `rustc`:\n```\n$ cargo --version\ncargo 1.47.0 (f3c7e066a 2020-08-28)\n\n$ rustc --version\nrustc 1.47.0 (18bf6b4f0 2020-10-07)\n```\n\n\n## Hands-on demo\n\nIn this demo we will approximate pi by generating random points and computing\ntheir distance to origin:\u003csup\u003e[1](#footnote1)\u003c/sup\u003e\n\n![random points](img/pi_Monte-Carlo.gif)\n\nTasks/discussion points:\n- Show how to bootstrap a project with `cargo new`\n- Step out of the newly bootstrapped project\n- Clone the code (this repository)\n- Browse and discuss the sources\n- Compile the sources with `cargo check`\n- Compare `cargo check` and `cargo build`\n- Discuss `cargo run`\n- Experiment with `cargo fmt`\n- Run the tests with `cargo test`\n- Generate optimized version with `cargo build --release`\n- Generate the documentation with `cargo doc`\n- Discuss `cargo publish` and https://crates.io (the Rust package registry)\n\n\n## Interfacing with C, C++, Fortran, and Python\n\n### C calling Rust and Fortran calling Rust\n\n```\ncargo build --release\n\ngfortran -L target/release/ -lpi examples/fortran/example.f90 -o fortran-example.x\ngcc -L target/release/ -lpi examples/c/example.c -o c-example.x\n\nenv LD_LIBRARY_PATH=target/release/ ./fortran-example.x\nenv LD_LIBRARY_PATH=target/release/ ./c-example.x\n```\n\n### Python calling Rust\n\nUsing [PyO3](https://github.com/PyO3/pyo3) and [Maturin](https://github.com/PyO3/maturin):\n```\ncargo build --release\nmaturin develop --release\npython -c \"import pi; print(pi.pi_approximation(1000000))\"\n```\n\n---\n\n\u003ca name=\"footnote1\"\u003e1\u003c/a\u003e: GIF from https://www.soroushjp.com/2015/02/07/go-concurrency-is-not-parallelism-real-world-lessons-with-monte-carlo-simulations/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-cafe%2Frust-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev-cafe%2Frust-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-cafe%2Frust-demo/lists"}