Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indent_style = "Block"
reorder_imports = false
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "rust-for-undergrads"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ Goals: To make it easy for undergrads to start programming in Rust. To advocate
Level: Beginner/Intermediate

Resources:

* [A Guide to Porting C/C++ to Rust](https://www.gitbook.com/book/locka99/a-guide-to-porting-c-to-rust/details)
* [Rust by Example](https://rustbyexample.com/)
* [Rustlings](https://github.com/carols10cents/rustlings)
* [Rosetta Code](http://rosettacode.org/wiki/Category:Rust)
* [exercism.io](http://exercism.io/languages/rust/about)


![Poster](https://github.com/rustindia/Rust-for-undergrads/blob/master/Rust_for_undergrads.png)

Community:

1. [rust-beginners](https://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-beginners), an IRC channel that loves answering questions at any depth.
2. [Rust Subreddit](https://www.reddit.com/r/rust), a place where Rust geeks love to engage.
3. [The Rust Users Forum](https://users.rust-lang.org/), for discussion of all things Rust.
Expand Down
9 changes: 9 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
#
# Usage example:
# bash lint.sh
#

echo "==> Formatting project files..."
cargo fmt --all
rustfmt src/*.rs
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly-2022-09-18"
components = ["rustfmt", "clippy"]
93 changes: 93 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
#
# Usage example:
# bash setup.sh -b
#

RUST_TOOLCHAIN="$(awk -F'[ ="]+' '$1 == "channel" { print $2 }' rust-toolchain.toml)"
INSTALL_BUILD_TOOLS="false"

function start_message() {
cat <<EOF
This script will download and install the necessary dependencies needed to
build, formating the scripts.

Based on your selection, these tools will be included:
EOF

if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then
cat <<EOF
Build tools (since -b or no option was provided):
* Rust (and the necessary components, e.g. rust-fmt, clippy)

EOF
fi

cat <<EOF
If you'd prefer to install these dependencies yourself, please use the command
Ctrl+C do exit the script.

EOF
}

function usage() {
echo "usage: $0 [-b] exchange method [...args]"
echo " -b Install build tools"
exit 1
}

function install_rustup {
RUST_TOOLCHAIN=$1

echo "==> Installing Rust......"
if rustup --version &>/dev/null; then
echo "Rust is already installed"
rustc --version
else
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain "${RUST_TOOLCHAIN}" --profile minimal
PATH="${HOME}/.cargo/bin:${PATH}"
source $HOME/.cargo/env
fi
}

function install_default_toolchain {
RUST_TOOLCHAIN=$1

echo "==> Setting nightly toolchain..."
rustup install "${RUST_TOOLCHAIN}"
rustup override set "${RUST_TOOLCHAIN}"

rustup component add rustfmt --toolchain "${RUST_TOOLCHAIN}"
rustup component add clippy --toolchain "${RUST_TOOLCHAIN}"
}

start_message

printf "Proceed with installing necessary dependencies? (y/N) > "
read -e -r input
if [[ "$input" != "y"* ]]; then
echo "Exiting..."
exit 0
fi

# Loop through command line arguments
while getopts "bc" arg; do
case "$arg" in
b)
INSTALL_BUILD_TOOLS="true"
;;
*)
usage exit 0
;;
esac
done

if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then
install_rustup "$RUST_TOOLCHAIN"
install_default_toolchain "$RUST_TOOLCHAIN"

# Any call to cargo will make rustup install the correct toolchain
cargo version
fi

echo "==> Rust configured!"
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Rust for Undergrads!");
}
Loading