create hello.rs program with some rust code example

This commit is contained in:
Antoine 2020-02-01 13:14:29 +01:00
commit 3624830881
4 changed files with 54 additions and 0 deletions

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "hello_world" # the name of the package
version = "0.1.0" # the current version, obeying semver
authors = ["Alice <a@example.com>", "Bob <b@example.com>"]
edition = '2018'
#build = "hello.rs"
publish = false
[dependencies]
rand = "0.7.3"

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM rust:1.40-alpine as builder
VOLUME /usr/local/cargo/bin/
WORKDIR /usr/src/myapp
COPY . .
RUN cargo install --root /usr/local --path .
#FROM debian:buster-slim
#
#RUN apt-get update && apt-get install -y extra-runtime-dependencies
#COPY --from=builder /usr/local/cargo/bin/myapp /usr/local/bin/myapp
#CMD ["hello"]
#CMD ["/usr/local/cargo/bin/hello"]
CMD sh -c "while true; do sleep 10; done"

11
Makefile Normal file
View File

@ -0,0 +1,11 @@
build: src/bin/*.rs Dockerfile
docker build -t my-rust-app .
run: build
docker rm -f rust-hello || true
docker run -d -it --rm --name rust-hello my-rust-app
exec:
docker exec -it rust-hello sh

17
src/bin/hello.rs Normal file
View File

@ -0,0 +1,17 @@
fn fair_dice_roll() -> i32 {
let x = vec![1, 2, 3, 4, 5, 6, 7, 8]
.iter()
.map(|x| x + 3)
.fold(0, |x, y| x + y);
return x;
}
fn main() {
let res = fair_dice_roll();
println!("{}", res);
}