diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..d69264d --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.101.0/containers/docker-existing-dockerfile +{ + "name": "Existing Dockerfile", + + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + + // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. + "dockerFile": "../Dockerfile", + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.shell.linux": null + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "kalitaalexey.vscode-rust", + "rust-lang.rust" + ] + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line to run commands after the container is created - for example installing git. + // "postCreateCommand": "apt-get update && apt-get install -y git", + + // Uncomment when using a ptrace-based debugger like C++, Go, and Rust + // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + + // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker. + // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], + + // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. + // "remoteUser": "vscode" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..72cec52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.env +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..79ee39d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,95 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "c2-chacha" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hello" +version = "0.1.0" +dependencies = [ + "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.66" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "ppv-lite86" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_chacha" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" +"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..997a555 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "hello" +version = "0.1.0" +authors = ["tamakiii"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rand = "0.7.3" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..44e487a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM rust:1.41.0-alpine3.11 AS production-pseudo + +RUN apk add --no-cache make bash && \ + sed -i -e 's|/bin/ash|/bin/bash|' /etc/passwd + +# -- + +FROM production-pseudo AS development + +ENV PAGER=less +ENV RUSTFLAGS -C target-feature=-crt-static + +RUN apk add --no-cache \ + git \ + bash-doc \ + bash-completion \ + openssl-dev \ + man \ + man-pages \ + coreutils-doc \ + cargo-doc \ + rust-doc \ + && \ + rustup component add rustfmt + +RUN mkdir -p ~/.local/share/bash-completion/completions && \ + rustup completions bash >> ~/.local/share/bash-completion/completions/rustup && \ + rustup toolchain add nightly && \ + rustup component add rust-analysis && \ + rustup component add rust-src && \ + rustup component add rls + +RUN cargo install cargo-edit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bd077a0 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: install run fmt clean + +install: + cargo install --path . + +build: + cargo $@ + +run: + cargo $@ + +check: + cargo $@ + +fmt: + cargo $@ + +clean: + cargo $@ + diff --git a/docker.mk b/docker.mk new file mode 100644 index 0000000..5de8997 --- /dev/null +++ b/docker.mk @@ -0,0 +1,38 @@ +.PHONY: init build ash bash run run/% make/% clean + +NAME := tamakiii-sandbox/hello-rust +WORK := /app +ENVIRONMENT := $(shell grep '^ENVIRONMENT=' .env | sed -E 's/ENVIRONMENT=//') +CMD := bash +VSC_NAME := vsc-hello-rust- + +init: \ + .env \ + build + +.env: + touch $@ + echo "ENVIRONMENT=production-pseudo" >> $@ + +build: + docker build -t $(NAME) --target $(ENVIRONMENT) . + +run: + docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) make run + +ash: run/ash +bash: run/bash + +run/%: + docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) $(@F) + +make/%: + docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) make $(@F) + +vsc: + docker exec -it $$(docker container ls | grep $(VSC_NAME) | awk '{ print $$1 }') $(CMD) + +clean: + rm .env + docker image rm $(NAME) + diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..f2b137c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,17 @@ +use std::io; +use rand::Rng; + +fn main() { + println!("Guess the number"); + println!("Please input your gess."); + + let mut guess = String::new(); + + io::stdin().read_line(&mut guess) + .expect("failed to read line!!"); + + let secret_number = rand::thread_rng().gen_range(1, 101); + + println!("You guessed: {}", guess); + println!("The secret number is: {}", secret_number); +}