From 3f2447dc2a7eaeac1400dcd4e13e515624915326 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Wed, 20 Sep 2023 23:28:19 +0900 Subject: [PATCH 01/26] Initial Commit. --- Cargo.lock | 150 +++++++++++++++++- .../external_crate_use/Cargo.toml | 17 ++ .../external_crate_use/README.md | 11 ++ .../external_crate_use/src/main.rs | 3 + 4 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 practice_collection/external_crate_use/Cargo.toml create mode 100644 practice_collection/external_crate_use/README.md create mode 100644 practice_collection/external_crate_use/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 107b14d..372138e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,6 +119,23 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "actix-session" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e6a28f813a6671e1847d005cad0be36ae4d016287690f765c303379837c13d6" +dependencies = [ + "actix-service", + "actix-utils", + "actix-web", + "anyhow", + "async-trait", + "derive_more", + "serde", + "serde_json", + "tracing", +] + [[package]] name = "actix-utils" version = "3.0.1" @@ -165,7 +182,7 @@ dependencies = [ "serde_urlencoded", "smallvec", "socket2 0.5.3", - "time 0.3.27", + "time", "url", ] @@ -196,6 +213,41 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + +[[package]] +name = "aes" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aes-gcm" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "209b47e8954a928e1d72e86eca7000ebb6655fe1436d33eefc2201cad027e237" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + [[package]] name = "ahash" version = "0.7.6" @@ -488,6 +540,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" + [[package]] name = "base64" version = "0.21.2" @@ -773,6 +831,16 @@ dependencies = [ "phf_codegen", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -806,7 +874,14 @@ version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" dependencies = [ + "aes-gcm", + "base64 0.20.0", + "hkdf", + "hmac", "percent-encoding", + "rand", + "sha2", + "subtle", "time", "version_check", ] @@ -957,6 +1032,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", + "rand_core", "typenum", ] @@ -981,6 +1057,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + [[package]] name = "darling" version = "0.13.4" @@ -1208,6 +1293,21 @@ dependencies = [ "zune-inflate", ] +[[package]] +name = "external_crate_use" +version = "0.1.0" +dependencies = [ + "actix-http", + "actix-session", + "actix-web", + "anyhow", + "dotenv", + "env_logger", + "log", + "mime", + "serde", +] + [[package]] name = "fallible-iterator" version = "0.2.0" @@ -1435,6 +1535,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "ghash" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d930750de5717d2dd0b8c0d42c076c0e884c81a73e6cab859bbd2339c71e3e40" +dependencies = [ + "opaque-debug", + "polyval", +] + [[package]] name = "gif" version = "0.12.0" @@ -1815,6 +1925,15 @@ dependencies = [ "syn 2.0.29", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + [[package]] name = "instant" version = "0.1.12" @@ -2159,6 +2278,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", + "log", "wasi", "windows-sys", ] @@ -2357,6 +2477,12 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "openssl" version = "0.10.56" @@ -2691,6 +2817,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "polyval" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52cff9d1d4dee5fe6d03729099f4a310a41179e0a10dbf542039873f2e826fb" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "postgres" version = "0.19.7" @@ -4421,6 +4559,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + [[package]] name = "untrusted" version = "0.7.1" diff --git a/practice_collection/external_crate_use/Cargo.toml b/practice_collection/external_crate_use/Cargo.toml new file mode 100644 index 0000000..abce3fb --- /dev/null +++ b/practice_collection/external_crate_use/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "external_crate_use" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +actix-session = { version = "0.8.0", features = ["cookie-session"] } +actix-http = "3.4.0" +actix-web = "4.4.0" +anyhow = "1.0.75" +dotenv = "0.15.0" +env_logger = "0.10.0" +log = "0.4.20" +mime = "0.3.17" +serde = { version = "1.0.0", features = ["derive"] } \ No newline at end of file diff --git a/practice_collection/external_crate_use/README.md b/practice_collection/external_crate_use/README.md new file mode 100644 index 0000000..c726ab4 --- /dev/null +++ b/practice_collection/external_crate_use/README.md @@ -0,0 +1,11 @@ +# 外部クレート活用 + +本格的なアプリケーションを作成するために知っていくと便利な外部クレートについて + +- 公開するサンプルアプリケーションの概要 +- セッション管理 +- 入力値検証 +- SSL/HTTP2対応 +- JWT認証 +- Actix Webのエラーハンドリング機能 +- アーキテクチャや内部実装 diff --git a/practice_collection/external_crate_use/src/main.rs b/practice_collection/external_crate_use/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/practice_collection/external_crate_use/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} From 95d59ebc88447a84d8267a604efb32db8407a1de Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Sat, 23 Sep 2023 21:45:46 +0900 Subject: [PATCH 02/26] openssl crate. --- .gitignore | 2 + Cargo.lock | 53 +++++++++++++++-- .../external_crate_use/Cargo.toml | 5 +- .../external_crate_use/README.md | 7 +++ .../external_crate_use/src/main.rs | 59 ++++++++++++++++++- practice_collection/web_framework/src/main.rs | 2 +- 6 files changed, 118 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 07e0677..d2fd525 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ rls/ *.iml .env .vscode +practice_collection/external_crate_use/local-key.pem +practice_collection/external_crate_use/local.pem diff --git a/Cargo.lock b/Cargo.lock index 372138e..e596ff7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,7 @@ dependencies = [ "actix-codec", "actix-rt", "actix-service", + "actix-tls", "actix-utils", "ahash 0.8.3", "base64 0.21.2", @@ -136,6 +137,27 @@ dependencies = [ "tracing", ] +[[package]] +name = "actix-tls" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72616e7fbec0aa99c6f3164677fa48ff5a60036d0799c98cab894a44f3e0efc3" +dependencies = [ + "actix-rt", + "actix-service", + "actix-utils", + "futures-core", + "impl-more", + "openssl", + "pin-project-lite", + "rustls 0.21.7", + "rustls-webpki", + "tokio", + "tokio-openssl", + "tokio-util", + "tracing", +] + [[package]] name = "actix-utils" version = "3.0.1" @@ -159,6 +181,7 @@ dependencies = [ "actix-rt", "actix-server", "actix-service", + "actix-tls", "actix-utils", "actix-web-codegen", "ahash 0.8.3", @@ -1305,6 +1328,7 @@ dependencies = [ "env_logger", "log", "mime", + "openssl", "serde", ] @@ -1894,6 +1918,12 @@ dependencies = [ "tiff", ] +[[package]] +name = "impl-more" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "206ca75c9c03ba3d4ace2460e57b189f39f43de612c2f85836e65c929701bb2d" + [[package]] name = "indexmap" version = "1.9.3" @@ -2485,11 +2515,11 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.56" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cfg-if", "foreign-types", "libc", @@ -2517,9 +2547,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.91" +version = "0.9.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" dependencies = [ "cc", "libc", @@ -3344,6 +3374,7 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ + "log", "ring", "rustls-webpki", "sct", @@ -4274,6 +4305,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-openssl" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08f9ffb7809f1b20c1b398d92acf4cc719874b3b2b2d9ea2f09b4a80350878a" +dependencies = [ + "futures-util", + "openssl", + "openssl-sys", + "tokio", +] + [[package]] name = "tokio-postgres" version = "0.7.10" diff --git a/practice_collection/external_crate_use/Cargo.toml b/practice_collection/external_crate_use/Cargo.toml index abce3fb..88d3035 100644 --- a/practice_collection/external_crate_use/Cargo.toml +++ b/practice_collection/external_crate_use/Cargo.toml @@ -8,10 +8,11 @@ edition = "2021" [dependencies] actix-session = { version = "0.8.0", features = ["cookie-session"] } actix-http = "3.4.0" -actix-web = "4.4.0" +actix-web = { version = "4.4.0", features = ["openssl"] } anyhow = "1.0.75" dotenv = "0.15.0" env_logger = "0.10.0" log = "0.4.20" mime = "0.3.17" -serde = { version = "1.0.0", features = ["derive"] } \ No newline at end of file +serde = { version = "1.0.0", features = ["derive"] } +openssl = { version ="0.10.57", features = ["v110"] } diff --git a/practice_collection/external_crate_use/README.md b/practice_collection/external_crate_use/README.md index c726ab4..fe54063 100644 --- a/practice_collection/external_crate_use/README.md +++ b/practice_collection/external_crate_use/README.md @@ -9,3 +9,10 @@ - JWT認証 - Actix Webのエラーハンドリング機能 - アーキテクチャや内部実装 + +## 証明書と秘密鍵 + +```sh +$ mkcert local +$ mkcert -install +``` diff --git a/practice_collection/external_crate_use/src/main.rs b/practice_collection/external_crate_use/src/main.rs index e7a11a9..ca63f6f 100644 --- a/practice_collection/external_crate_use/src/main.rs +++ b/practice_collection/external_crate_use/src/main.rs @@ -1,3 +1,58 @@ -fn main() { - println!("Hello, world!"); +use actix_web::{ + middleware, + web::{self, resource, ServiceConfig}, + cookie::time::Duration, + App, HttpServer, HttpResponse, Responder, +}; +use actix_session::config::BrowserSession; +use actix_session::SessionMiddleware; +use actix_session::storage::CookieSessionStore; +use openssl::ssl::{SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod}; + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + let key = actix_web::cookie::Key::generate(); + + HttpServer::new(move || { + App::new() + .wrap(middleware::Logger::default()) + .wrap( + SessionMiddleware::builder( + CookieSessionStore::default(), key.clone() + ) + .session_lifecycle( + BrowserSession::default().state_ttl(Duration::minutes(5)) + ) + .cookie_name("rsessionid".to_string()) + .build() + ) + .service( + web::scope("/v2") + .configure(set_configure) + ) + .route("/", web::get().to(|| HttpResponse::Ok())) + }).bind_openssl("127.0.0.1:8082", create_ssl_accepter_builder())? + .run() + .await } + +fn set_configure(cfg: &mut ServiceConfig) { + cfg.service( + resource("/health") + .route(web::get().to(health)) + ); +} +async fn health() -> impl Responder { + + HttpResponse::Ok().content_type(mime::APPLICATION_JSON).json(r#"{"health": "Ok"}"#) +} +// openssl crate +fn create_ssl_accepter_builder() -> SslAcceptorBuilder { + // OpenSSL構造を管理し、暗号スイート、セッションオプションなどを構成する + let mut builder: SslAcceptorBuilder = + SslAcceptor::mozilla_intermediate_v5(SslMethod::tls_server()).unwrap(); + builder.set_private_key_file("local-key.pem", SslFiletype::PEM).unwrap(); + builder.set_certificate_chain_file("local.pem").unwrap(); + builder +} \ No newline at end of file diff --git a/practice_collection/web_framework/src/main.rs b/practice_collection/web_framework/src/main.rs index 6c1e7d3..2ecc3b9 100644 --- a/practice_collection/web_framework/src/main.rs +++ b/practice_collection/web_framework/src/main.rs @@ -22,7 +22,7 @@ async fn main() -> Result<(), std::io::Error> { .configure(set_configure), ) }) - .bind("127.0.0.1:8081")? + .bind("127.0.0.1:8082")? //.workers(2) // default Number of physical cores .run() .await From 184176196f4ff9c72818149c71aad5bcc88847af Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Sat, 21 Oct 2023 00:52:35 +0900 Subject: [PATCH 03/26] =?UTF-8?q?docker=20compose=20watch=20=E3=82=B3?= =?UTF-8?q?=E3=83=9E=E3=83=B3=E3=83=89=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web_framework/.dockerignore | 32 +++++++++ practice_collection/web_framework/Dockerfile | 69 +++++++++++++++++++ practice_collection/web_framework/READNE.md | 1 + .../web_framework/compose.yaml | 57 +++++++++++++++ practice_collection/web_framework/src/main.rs | 2 +- 5 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 practice_collection/web_framework/.dockerignore create mode 100644 practice_collection/web_framework/Dockerfile create mode 100644 practice_collection/web_framework/compose.yaml diff --git a/practice_collection/web_framework/.dockerignore b/practice_collection/web_framework/.dockerignore new file mode 100644 index 0000000..3dfba38 --- /dev/null +++ b/practice_collection/web_framework/.dockerignore @@ -0,0 +1,32 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/engine/reference/builder/#dockerignore-file + +**/.DS_Store +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/secrets.dev.yaml +**/values.dev.yaml +/bin +/target +LICENSE +README.md diff --git a/practice_collection/web_framework/Dockerfile b/practice_collection/web_framework/Dockerfile new file mode 100644 index 0000000..0826f48 --- /dev/null +++ b/practice_collection/web_framework/Dockerfile @@ -0,0 +1,69 @@ +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/engine/reference/builder/ + +################################################################################ +# Create a stage for building the application. + +ARG RUST_VERSION=1.73.0 +ARG APP_NAME=web_framework +FROM rust:${RUST_VERSION}-slim-bullseye AS build +ARG APP_NAME +WORKDIR /app + +# Build the application. +# Leverage a cache mount to /usr/local/cargo/registry/ +# for downloaded dependencies and a cache mount to /app/target/ for +# compiled dependencies which will speed up subsequent builds. +# Leverage a bind mount to the src directory to avoid having to copy the +# source code into the container. Once built, copy the executable to an +# output directory before the cache mounted /app/target is unmounted. +RUN --mount=type=bind,source=src,target=src \ + --mount=type=bind,source=Cargo.toml,target=Cargo.toml \ +## --mount=type=bind,source=Cargo.lock,target=Cargo.lock \ + --mount=type=bind,source=views,target=views \ + --mount=type=cache,target=/app/target/ \ + --mount=type=cache,target=/usr/local/cargo/registry/ \ + < +- | クレート | 機能 | | ---------- | ------------------------------------------------------------------- | diff --git a/practice_collection/web_framework/compose.yaml b/practice_collection/web_framework/compose.yaml new file mode 100644 index 0000000..4d97de1 --- /dev/null +++ b/practice_collection/web_framework/compose.yaml @@ -0,0 +1,57 @@ +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Docker compose reference guide at +# https://docs.docker.com/compose/compose-file/ + +# Here the instructions define your application as a service called "server". +# This service is built from the Dockerfile in the current directory. +# You can add other services your application may depend on here, such as a +# database or a cache. For examples, see the Awesome Compose repository: +# https://github.com/docker/awesome-compose +services: + server: + build: + context: . + target: final + ports: + - 8082:8082 + + develop: + watch: + - action: rebuild + path: ./src + - action: rebuild + path: ./templates + +# The commented out section below is an example of how to define a PostgreSQL +# database that your application can use. `depends_on` tells Docker Compose to +# start the database before your application. The `db-data` volume persists the +# database data between container restarts. The `db-password` secret is used +# to set the database password. You must create `db/password.txt` and add +# a password of your choosing to it before running `docker compose up`. +# depends_on: +# db: +# condition: service_healthy +# db: +# image: postgres +# restart: always +# user: postgres +# secrets: +# - db-password +# volumes: +# - db-data:/var/lib/postgresql/data +# environment: +# - POSTGRES_DB=example +# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password +# expose: +# - 5432 +# healthcheck: +# test: [ "CMD", "pg_isready" ] +# interval: 10s +# timeout: 5s +# retries: 5 +# volumes: +# db-data: +# secrets: +# db-password: +# file: db/password.txt + diff --git a/practice_collection/web_framework/src/main.rs b/practice_collection/web_framework/src/main.rs index 2ecc3b9..3197ae9 100644 --- a/practice_collection/web_framework/src/main.rs +++ b/practice_collection/web_framework/src/main.rs @@ -22,7 +22,7 @@ async fn main() -> Result<(), std::io::Error> { .configure(set_configure), ) }) - .bind("127.0.0.1:8082")? + .bind("0.0.0.0:8082")? //.workers(2) // default Number of physical cores .run() .await From 8700b317688fbce46a090d05754f8ad50a7c4232 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Thu, 2 Nov 2023 19:13:35 +0900 Subject: [PATCH 04/26] test_trait_and_struct_01 --- iriam_profile/src/main.rs | 106 ++++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 26 deletions(-) diff --git a/iriam_profile/src/main.rs b/iriam_profile/src/main.rs index a7d6791..0d02a31 100644 --- a/iriam_profile/src/main.rs +++ b/iriam_profile/src/main.rs @@ -1,4 +1,4 @@ -use std::fmt::{Display, Error, Formatter}; + type S = LiveStreamer; #[derive(Debug, Default, Clone)] struct LiveStreamer { @@ -6,6 +6,16 @@ struct LiveStreamer { mark: Option, x_name: Option, } +impl LiveStreamer { + fn _printer(&self) { + println!( + "{}{}{} Liked♡", + self.name.clone().unwrap_or_default(), + self.mark.clone().unwrap_or_default(), + self.x_name.clone().unwrap_or_default() + ) + } +} struct Builder(LiveStreamer); fn main() { let streamer = vec![ @@ -18,15 +28,16 @@ fn main() { Builder::new().with_mark("📘📗🌼").build(), Builder::new().with_mark("🐈‍⬛💜.*・").build(), ]; - let printer = |s: S| { + let printer = |s: &S| { println!( "{} Liked♡", - s.name.unwrap_or_default() - + &s.mark.unwrap_or_default() - + &s.x_name.unwrap_or_default() + s.name.clone().unwrap_or_default() + + s.mark.clone().unwrap_or_default().as_str() + + s.x_name.clone().unwrap_or_default().as_str() ) }; - streamer.into_iter().for_each(printer); + streamer.iter().for_each(|s| printer(s)); + streamer.into_iter().for_each(|s| printer(&s)); } impl Builder { fn new() -> Self { @@ -34,13 +45,13 @@ impl Builder { } fn with_name(&self, name: &str) -> Self { Builder(LiveStreamer { - name: Some(name.to_string()), + name: Some(name.to_string().clone()), ..self.0.clone() }) } fn with_mark(&self, mark: &str) -> Self { Builder(LiveStreamer { - mark: Some(mark.to_string()), + mark: Some(mark.to_string().clone()), ..self.0.clone() }) } @@ -48,24 +59,6 @@ impl Builder { self.0 } } -impl LiveStreamer { - #[allow(dead_code)] - fn new(name: Option, mark: Option, x_name: Option) -> Self { - Self { name, mark, x_name } - } -} -impl Display for LiveStreamer { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { - write!( - f, - "name: {}, mark: {} x: {}", - self.name.as_ref().unwrap(), - self.mark.as_ref().unwrap(), - self.x_name.as_ref().unwrap() - )?; - Ok(()) - } -} #[allow(dead_code)] fn str_sort() { @@ -87,3 +80,64 @@ fn str_sort() { fn str_sort_test() { str_sort(); } + +#[test] +fn test_loop() { + for i in 2 as i128.. { + println!("{i}"); + if i >= i16::MAX.into() { + break; + } + } +} + +#[test] +fn test_tuple() { + + #[derive(Debug)] + struct Tuple3 { + a: T, + b: T, + c: T + } + #[derive(Debug)] + struct Tuple3Ver2(T,T,T); + + impl From<(T, T, T)> for Tuple3 { + fn from(value: (T, T, T)) -> Self { + Self { + a: value.0, + b: value.1, + c: value.2 + } + } + } + + + let _tuple_mix_type = ("hello", 5, 'c'); + let tuple_one_type = ("hello", "hello", "c"); + + let three_tuple = tuple_one_type.clone(); + + let instance = Tuple3::<&str>::from(three_tuple); + println!("{:?}", instance) + +} + +#[test] +fn test_trait_and_struct_01() { + trait MyTrait { + fn test(_: T) -> AT; + } + struct MyStruct(i32, i32); + + impl MyTrait for MyStruct { + fn test(v: MyStruct) -> i32 { + v.0 + v.1 + } + } + + let my_instance = MyStruct(10, 10); + let ans = >::test(my_instance); + assert_eq!(ans, 20); +} \ No newline at end of file From 49142c9ffc8f85ade455601091b1b7616bee7700 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Thu, 2 Nov 2023 19:47:34 +0900 Subject: [PATCH 05/26] [clippy error]fix &str not implement `Clone` --- examples/l08_struct/src/member.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/l08_struct/src/member.rs b/examples/l08_struct/src/member.rs index bc0ce0f..66cc544 100644 --- a/examples/l08_struct/src/member.rs +++ b/examples/l08_struct/src/member.rs @@ -19,7 +19,7 @@ impl<'a> Member<'a> { #[allow(dead_code)] fn get_name(&self) -> &str { - self.name.clone() + self.name } #[allow(dead_code)] From 34979f95bba39ac98bd3c99b7ea41c71bb27e210 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Sat, 11 Nov 2023 07:28:08 +0900 Subject: [PATCH 06/26] fix warning --- .resource/license_header | 4 ++ Cargo.lock | 111 +++++++++++++++++++++++++++++++++++++- build.rs | 48 +++++++++++++++++ iriam_profile/src/main.rs | 12 ++--- 4 files changed, 167 insertions(+), 8 deletions(-) create mode 100644 .resource/license_header create mode 100644 build.rs diff --git a/.resource/license_header b/.resource/license_header new file mode 100644 index 0000000..a8b2007 --- /dev/null +++ b/.resource/license_header @@ -0,0 +1,4 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index e596ff7..3d17584 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -542,6 +542,63 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +dependencies = [ + "async-trait", + "axum-core", + "bitflags 1.3.2", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum_web_framework" +version = "0.1.0" +dependencies = [ + "axum", + "tokio", +] + [[package]] name = "backtrace" version = "0.3.68" @@ -2245,6 +2302,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "md-5" version = "0.10.5" @@ -3399,6 +3462,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.15" @@ -3627,6 +3696,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -4105,6 +4184,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "take_mut" version = "0.2.2" @@ -4267,9 +4352,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" dependencies = [ "backtrace", "bytes", @@ -4397,6 +4482,28 @@ dependencies = [ "reqwest", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..2416b0b --- /dev/null +++ b/build.rs @@ -0,0 +1,48 @@ +use std::{fs::File, io::Read, path::Path}; + +use walkdir::WalkDir; + +// The following license text that should be present at the beginning of every source file. +const EXPECTED_LICENSE_TEXT: &[u8] = include_bytes!(".resources/license_header"); + +// The following directories will be excluded from the license scan. +const DIRS_TO_SKIP: [&str; 8] = [".cargo", ".circleci", ".git", ".github", ".resources", "examples", "js", "target"]; + +fn check_file_licenses>(path: P) { + let path = path.as_ref(); + + let mut iter = WalkDir::new(path).into_iter(); + while let Some(entry) = iter.next() { + let entry = entry.unwrap(); + let entry_type = entry.file_type(); + + // Skip the specified directories. + if entry_type.is_dir() && DIRS_TO_SKIP.contains(&entry.file_name().to_str().unwrap_or("")) { + iter.skip_current_dir(); + + continue; + } + + // Check all files with the ".rs" extension. + if entry_type.is_file() && entry.file_name().to_str().unwrap_or("").ends_with(".rs") { + let file = File::open(entry.path()).unwrap(); + let mut contents = Vec::with_capacity(EXPECTED_LICENSE_TEXT.len()); + file.take(EXPECTED_LICENSE_TEXT.len() as u64).read_to_end(&mut contents).unwrap(); + + assert!( + contents == EXPECTED_LICENSE_TEXT, + "The license in \"{}\" is either missing or it doesn't match the expected string!", + entry.path().display() + ); + } + } + + // Re-run upon any changes to the workspace. + println!("cargo:rerun-if-changed=."); +} + +// The build script; it currently only checks the licenses. +fn main() { + // Check licenses in the current folder. + check_file_licenses("."); +} \ No newline at end of file diff --git a/iriam_profile/src/main.rs b/iriam_profile/src/main.rs index 0d02a31..5659e59 100644 --- a/iriam_profile/src/main.rs +++ b/iriam_profile/src/main.rs @@ -96,9 +96,9 @@ fn test_tuple() { #[derive(Debug)] struct Tuple3 { - a: T, - b: T, - c: T + _a: T, + _b: T, + _c: T } #[derive(Debug)] struct Tuple3Ver2(T,T,T); @@ -106,9 +106,9 @@ fn test_tuple() { impl From<(T, T, T)> for Tuple3 { fn from(value: (T, T, T)) -> Self { Self { - a: value.0, - b: value.1, - c: value.2 + _a: value.0, + _b: value.1, + _c: value.2 } } } From df50c98662c1beafee9ded426e68828550e7a74c Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Sat, 11 Nov 2023 07:41:21 +0900 Subject: [PATCH 07/26] change MyTrait hello_world MyStruct(String, String) --- iriam_profile/src/main.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/iriam_profile/src/main.rs b/iriam_profile/src/main.rs index 5659e59..3fba868 100644 --- a/iriam_profile/src/main.rs +++ b/iriam_profile/src/main.rs @@ -127,17 +127,18 @@ fn test_tuple() { #[test] fn test_trait_and_struct_01() { trait MyTrait { - fn test(_: T) -> AT; + fn hello_world(_: T) -> AT; } - struct MyStruct(i32, i32); + struct MyStruct(String, String); - impl MyTrait for MyStruct { - fn test(v: MyStruct) -> i32 { - v.0 + v.1 + impl MyTrait for MyStruct { + fn hello_world(v: MyStruct) -> String { + format!("My name is {} {}", v.0, v.1) } } - let my_instance = MyStruct(10, 10); - let ans = >::test(my_instance); - assert_eq!(ans, 20); + let my_instance = MyStruct("T".to_owned(), "Kumagai".to_owned()); + let ans = >::hello_world(my_instance); + println!("{ans}"); + assert_eq!(ans, "My name is T Kumagai".to_string()); } \ No newline at end of file From 43ff38ca7358fbc013c5d4c27cff4e630635bf47 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:01:37 +0900 Subject: [PATCH 08/26] create sample dotenv and update hello world. --- Cargo.lock | 310 +++++++++++++++++++--- Cargo.toml | 5 +- examples/dotenv_parser_sample/Cargo.toml | 17 ++ examples/dotenv_parser_sample/src/main.rs | 17 ++ my_rust_version_hello_world/Cargo.toml | 15 ++ my_rust_version_hello_world/README.md | 0 my_rust_version_hello_world/src/main.rs | 18 ++ 7 files changed, 350 insertions(+), 32 deletions(-) create mode 100644 examples/dotenv_parser_sample/Cargo.toml create mode 100644 examples/dotenv_parser_sample/src/main.rs create mode 100644 my_rust_version_hello_world/Cargo.toml create mode 100644 my_rust_version_hello_world/README.md create mode 100644 my_rust_version_hello_world/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 3d17584..a95d389 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -345,6 +345,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3a318f1f38d2418400f8209655bfd825785afd25aa30bb7ba6cc792e4596748" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -451,7 +499,7 @@ dependencies = [ "futures-lite", "rustix 0.37.23", "signal-hook", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -536,6 +584,17 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -886,7 +945,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -921,12 +980,82 @@ dependencies = [ "inout", ] +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags 1.3.2", + "clap_lex 0.2.4", + "indexmap 1.9.3", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap" +version = "4.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" +dependencies = [ + "anstream", + "anstyle", + "clap_lex 0.6.0", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.29", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + [[package]] name = "color_quant" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "concurrent-queue" version = "2.2.0" @@ -1255,11 +1384,35 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +[[package]] +name = "dotenv_parser_sample" +version = "0.1.0" +dependencies = [ + "clap 4.4.11", + "dotenvy", + "dotenvy_macro", +] + [[package]] name = "dotenvy" version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +dependencies = [ + "clap 3.2.25", +] + +[[package]] +name = "dotenvy_macro" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0235d912a8c749f4e0c9f18ca253b4c28cfefc1d2518096016d6e3230b6424" +dependencies = [ + "dotenvy", + "proc-macro2", + "quote", + "syn 1.0.109", +] [[package]] name = "either" @@ -1318,7 +1471,7 @@ checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1348,7 +1501,7 @@ checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" dependencies = [ "cfg-if", "home", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1743,6 +1896,15 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.2" @@ -1779,7 +1941,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2036,9 +2198,9 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.2", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2049,7 +2211,7 @@ checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ "socket2 0.5.3", "widestring", - "windows-sys", + "windows-sys 0.48.0", "winreg", ] @@ -2069,9 +2231,9 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.2", "rustix 0.38.8", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2373,7 +2535,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2438,6 +2600,10 @@ dependencies = [ "webpki-roots 0.22.6", ] +[[package]] +name = "my_rust_version_hello_world" +version = "0.1.0" + [[package]] name = "nanorand" version = "0.7.0" @@ -2551,7 +2717,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.2", "libc", ] @@ -2647,6 +2813,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + [[package]] name = "ouroboros" version = "0.17.2" @@ -2697,7 +2869,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2907,7 +3079,7 @@ dependencies = [ "libc", "log", "pin-project-lite", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3403,7 +3575,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys 0.3.8", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3416,7 +3588,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.5", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3489,7 +3661,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3872,7 +4044,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -4212,7 +4384,7 @@ dependencies = [ "fastrand 2.0.0", "redox_syscall", "rustix 0.38.8", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -4253,6 +4425,12 @@ dependencies = [ "simple_test_case", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thiserror" version = "1.0.48" @@ -4366,7 +4544,7 @@ dependencies = [ "signal-hook-registry", "socket2 0.5.3", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -4736,6 +4914,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.4.1" @@ -4973,7 +5157,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -4982,7 +5166,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -4991,13 +5184,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] @@ -5006,42 +5214,84 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "winreg" version = "0.50.0" @@ -5049,7 +5299,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ "cfg-if", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9aa2204..7036c4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,12 @@ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace] -resolver = "1" +resolver = "2" members = [ "examples/*", "practice_collection/*", - "iriam_profile/" + "iriam_profile/", + "my_rust_version_hello_world/" ] #[dependencies] \ No newline at end of file diff --git a/examples/dotenv_parser_sample/Cargo.toml b/examples/dotenv_parser_sample/Cargo.toml new file mode 100644 index 0000000..3685e99 --- /dev/null +++ b/examples/dotenv_parser_sample/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "dotenv_parser_sample" +version = "0.1.0" +edition = "2021" +readme = "README.md" +keywords = ["dotenv", "env", "environment", "settings", "config"] +license = "MIT" +homepage = "https://github.com/frendbear/perfect-rust" +repository = "https://github.com/friendbear/perfect-rust/examples/dotenv_perser_sample" +description = "A macro for compile time dotenv inspection" +rust-version = "1.74.0" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.4.11", features = ["derive", "env"] } +dotenvy = { version = "0.15.7", features = ["clap", "cli"] } +dotenvy_macro = "0.15.7" diff --git a/examples/dotenv_parser_sample/src/main.rs b/examples/dotenv_parser_sample/src/main.rs new file mode 100644 index 0000000..cb4fbbf --- /dev/null +++ b/examples/dotenv_parser_sample/src/main.rs @@ -0,0 +1,17 @@ +//use dotenvy::dotenv; +//use dotenvy_macro; +use clap::Parser; + +#[derive(Debug, Parser)] +struct Config { + #[arg(long, env, hide_env_values = true)] + host: String, + #[arg(long, env, hide_env_values = true)] + port: u16, +} +fn main() { + + let config = Config::parse(); + + dbg!(&config); +} diff --git a/my_rust_version_hello_world/Cargo.toml b/my_rust_version_hello_world/Cargo.toml new file mode 100644 index 0000000..b87287b --- /dev/null +++ b/my_rust_version_hello_world/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "my_rust_version_hello_world" +version = "0.1.1" +edition = "2021" + +readme = "README.md" +keywords = ["hello-world", "rust-lang"] +license = "MIT" +homepage = "https://github.com/friendbear/perfect-rust" +repository = "https://github.com/friendbear/perfect-rust/my_rust_version_hello_world" +description = "" +rust-version = "1.74.0" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/my_rust_version_hello_world/README.md b/my_rust_version_hello_world/README.md new file mode 100644 index 0000000..e69de29 diff --git a/my_rust_version_hello_world/src/main.rs b/my_rust_version_hello_world/src/main.rs new file mode 100644 index 0000000..2db310e --- /dev/null +++ b/my_rust_version_hello_world/src/main.rs @@ -0,0 +1,18 @@ + +fn main() { + trait MyTrait { + fn hello_world(_: T) -> AT; + } + struct MyStruct(String, String); + + impl MyTrait for MyStruct { + fn hello_world(v: MyStruct) -> String { + format!("Hello world, My name is {} {}", v.0, v.1) + } + } + + let my_instance = MyStruct("T".to_owned(), "Kumagai".to_owned()); + let hello_world_string = >::hello_world(my_instance); + println!("{hello_world_string}"); + assert_eq!(hello_world_string, "Hello world, My name is T Kumagai".to_string()); +} From f7364cfb45a72a6dcd188f22345d9efb58fda7e2 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Fri, 8 Dec 2023 03:49:39 +0900 Subject: [PATCH 09/26] fix clippy error 1.74.0 --- examples/l07_function/src/option_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/l07_function/src/option_type.rs b/examples/l07_function/src/option_type.rs index 3e307a4..61714d2 100644 --- a/examples/l07_function/src/option_type.rs +++ b/examples/l07_function/src/option_type.rs @@ -72,7 +72,7 @@ mod test_option_type { Some(1).map(|some_value| some_value.to_string()), Some("1".to_owned()) ); - assert_eq!(Some(1).map(closure), Some("1".to_owned())); + assert_eq!(Some(closure(1)), Some("1".to_owned())); assert_eq!(None.map(|some_value: &str| some_value.len()), None); assert_eq!( From fb24c123539956e6f2bebb19bbe4ad36698bfe85 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Sat, 9 Dec 2023 22:57:35 +0900 Subject: [PATCH 10/26] Update dependabot.yml --- .github/dependabot.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4e30578..b504e0c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,12 @@ version: 2 updates: - - package-ecosystem: "cargo" # See documentation for possible values - directory: "/" # Location of package manifests + - package-ecosystem: “cargo” + directory: "/" schedule: - interval: "daily" + interval: "weekly" + # Add assignees + assignees: + - “friendbear” + commit-message: + - prefix: ‘[Cargo]” From fe1ce1e45904124c70e6995fa66317c64bf7a223 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:32:31 +0000 Subject: [PATCH 11/26] add [[package]] --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4266a94..ef582f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4365,7 +4365,7 @@ dependencies = [ "core-foundation-sys", "libc", ] - +[[package]] name = "sync_wrapper" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" From 68535b862bba986e8261a59e48065f4d905b1fad Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:58:25 +0000 Subject: [PATCH 12/26] rename folder --- Cargo.lock | 112 +----------------- Cargo.toml | 2 +- .../Cargo.toml | 6 +- .../README.md | 0 .../src/main.rs | 0 5 files changed, 7 insertions(+), 113 deletions(-) rename {my_rust_version_hello_world => my-rust-version-hello-world}/Cargo.toml (63%) rename {my_rust_version_hello_world => my-rust-version-hello-world}/README.md (100%) rename {my_rust_version_hello_world => my-rust-version-hello-world}/src/main.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index ef582f4..122980f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,7 +150,7 @@ dependencies = [ "impl-more", "openssl", "pin-project-lite", - "rustls 0.21.7", + "rustls", "rustls-webpki", "tokio", "tokio-openssl", @@ -601,63 +601,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "axum" -version = "0.6.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" -dependencies = [ - "async-trait", - "axum-core", - "bitflags 1.3.2", - "bytes", - "futures-util", - "http", - "http-body", - "hyper", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "serde_json", - "serde_path_to_error", - "serde_urlencoded", - "sync_wrapper", - "tokio", - "tower", - "tower-layer", - "tower-service", -] - -[[package]] -name = "axum-core" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "mime", - "rustversion", - "tower-layer", - "tower-service", -] - -[[package]] -name = "axum_web_framework" -version = "0.1.0" -dependencies = [ - "axum", - "tokio", -] - [[package]] name = "backtrace" version = "0.3.68" @@ -2464,12 +2407,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" -[[package]] -name = "matchit" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" - [[package]] name = "md-5" version = "0.10.5" @@ -2601,8 +2538,8 @@ dependencies = [ ] [[package]] -name = "my_rust_version_hello_world" -version = "0.1.0" +name = "my-rust-version-hello-world" +version = "0.1.1" [[package]] name = "nanorand" @@ -3623,12 +3560,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - [[package]] name = "ryu" version = "1.0.15" @@ -3857,16 +3788,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_path_to_error" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" -dependencies = [ - "itoa", - "serde", -] - [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -4365,11 +4286,6 @@ dependencies = [ "core-foundation-sys", "libc", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "take_mut" @@ -4668,28 +4584,6 @@ dependencies = [ "reqwest", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - [[package]] name = "tower-service" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index 7036c4c..bfc6150 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ members = [ "examples/*", "practice_collection/*", "iriam_profile/", - "my_rust_version_hello_world/" + "my-rust-version-hello-world/" ] #[dependencies] \ No newline at end of file diff --git a/my_rust_version_hello_world/Cargo.toml b/my-rust-version-hello-world/Cargo.toml similarity index 63% rename from my_rust_version_hello_world/Cargo.toml rename to my-rust-version-hello-world/Cargo.toml index b87287b..b487e90 100644 --- a/my_rust_version_hello_world/Cargo.toml +++ b/my-rust-version-hello-world/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "my_rust_version_hello_world" +name = "my-rust-version-hello-world" version = "0.1.1" edition = "2021" @@ -7,8 +7,8 @@ readme = "README.md" keywords = ["hello-world", "rust-lang"] license = "MIT" homepage = "https://github.com/friendbear/perfect-rust" -repository = "https://github.com/friendbear/perfect-rust/my_rust_version_hello_world" -description = "" +repository = "https://github.com/friendbear/perfect-rust/my-rust-version-hello-world" +description = "Rust Lang version hello world starting here." rust-version = "1.74.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/my_rust_version_hello_world/README.md b/my-rust-version-hello-world/README.md similarity index 100% rename from my_rust_version_hello_world/README.md rename to my-rust-version-hello-world/README.md diff --git a/my_rust_version_hello_world/src/main.rs b/my-rust-version-hello-world/src/main.rs similarity index 100% rename from my_rust_version_hello_world/src/main.rs rename to my-rust-version-hello-world/src/main.rs From 593cf5d5c79ae69753cbce50c9b5320f7062b9c8 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:04:15 +0000 Subject: [PATCH 13/26] fix clippy warning. --- examples/l06_library_data_type/src/hash_map_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/l06_library_data_type/src/hash_map_type.rs b/examples/l06_library_data_type/src/hash_map_type.rs index eaacb43..fffe590 100644 --- a/examples/l06_library_data_type/src/hash_map_type.rs +++ b/examples/l06_library_data_type/src/hash_map_type.rs @@ -50,7 +50,7 @@ mod test_hash_map_type { assert!(map_x.contains_key(&2)); assert_eq!(map_x.get_key_value(&2).unwrap(), (&(2_i64), &"DEF")); - for k in map_x.keys() { + if let Some(k) = map_x.keys().next() { match k { 1 | 2 | 10 => return, _ => unreachable!(), From 3b3589716ff84752013659324c91f8b7163cf5c2 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:46:26 +0000 Subject: [PATCH 14/26] fix #[allow(clippy::needless_return)] --- examples/l06_library_data_type/src/hash_map_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/l06_library_data_type/src/hash_map_type.rs b/examples/l06_library_data_type/src/hash_map_type.rs index fffe590..ca6303c 100644 --- a/examples/l06_library_data_type/src/hash_map_type.rs +++ b/examples/l06_library_data_type/src/hash_map_type.rs @@ -52,7 +52,7 @@ mod test_hash_map_type { if let Some(k) = map_x.keys().next() { match k { - 1 | 2 | 10 => return, + 1 | 2 | 10 => ()), _ => unreachable!(), } } From eb0cf3af70766db8cf075d13b10ba90d3f7290d6 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:47:31 +0000 Subject: [PATCH 15/26] fix #[allow(clippy::needless_return)] --- examples/l06_library_data_type/src/hash_map_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/l06_library_data_type/src/hash_map_type.rs b/examples/l06_library_data_type/src/hash_map_type.rs index ca6303c..211700c 100644 --- a/examples/l06_library_data_type/src/hash_map_type.rs +++ b/examples/l06_library_data_type/src/hash_map_type.rs @@ -52,7 +52,7 @@ mod test_hash_map_type { if let Some(k) = map_x.keys().next() { match k { - 1 | 2 | 10 => ()), + 1 | 2 | 10 => (), _ => unreachable!(), } } From 4b7ea4bf498a2b4a3a1712589c1302bf9a991bb2 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:28:05 +0000 Subject: [PATCH 16/26] rename and fix clippy warning. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- {iriam_profile => iriam-profile}/Cargo.lock | 2 +- {iriam_profile => iriam-profile}/Cargo.toml | 4 ++-- {iriam_profile => iriam-profile}/Makefile.toml | 0 iriam-profile/README.md | 8 ++++++++ {iriam_profile => iriam-profile}/src/main.rs | 14 ++++++++++---- my-rust-version-hello-world/src/main.rs | 6 +++++- 8 files changed, 29 insertions(+), 11 deletions(-) rename {iriam_profile => iriam-profile}/Cargo.lock (88%) rename {iriam_profile => iriam-profile}/Cargo.toml (77%) rename {iriam_profile => iriam-profile}/Makefile.toml (100%) create mode 100644 iriam-profile/README.md rename {iriam_profile => iriam-profile}/src/main.rs (87%) diff --git a/Cargo.lock b/Cargo.lock index 122980f..4d1e95d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2165,8 +2165,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" [[package]] -name = "iriam_profile" -version = "0.1.0" +name = "iriam-profile" +version = "0.1.1" [[package]] name = "is-terminal" diff --git a/Cargo.toml b/Cargo.toml index bfc6150..658ceca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ resolver = "2" members = [ "examples/*", "practice_collection/*", - "iriam_profile/", + "iriam-profile/", "my-rust-version-hello-world/" ] diff --git a/iriam_profile/Cargo.lock b/iriam-profile/Cargo.lock similarity index 88% rename from iriam_profile/Cargo.lock rename to iriam-profile/Cargo.lock index 38dbaca..44eb95f 100644 --- a/iriam_profile/Cargo.lock +++ b/iriam-profile/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "iriam-profile" -version = "0.1.0" +version = "0.1.1" diff --git a/iriam_profile/Cargo.toml b/iriam-profile/Cargo.toml similarity index 77% rename from iriam_profile/Cargo.toml rename to iriam-profile/Cargo.toml index a24b7e1..b6fa4d5 100644 --- a/iriam_profile/Cargo.toml +++ b/iriam-profile/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "iriam_profile" -version = "0.1.0" +name = "iriam-profile" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/iriam_profile/Makefile.toml b/iriam-profile/Makefile.toml similarity index 100% rename from iriam_profile/Makefile.toml rename to iriam-profile/Makefile.toml diff --git a/iriam-profile/README.md b/iriam-profile/README.md new file mode 100644 index 0000000..498f7dd --- /dev/null +++ b/iriam-profile/README.md @@ -0,0 +1,8 @@ +# About this + + 気になったコードを書き綴って行くcargo project です。 + + 面白そうなコードはここで書いて試したのち、問題や課題、解決できない場合や疑問は以下の**rust-lang** フォーラムで質問した上で + 別レポジトリに切り出します。 + +* diff --git a/iriam_profile/src/main.rs b/iriam-profile/src/main.rs similarity index 87% rename from iriam_profile/src/main.rs rename to iriam-profile/src/main.rs index 3fba868..b2e6eb4 100644 --- a/iriam_profile/src/main.rs +++ b/iriam-profile/src/main.rs @@ -24,7 +24,9 @@ fn main() { .with_name("はしちゃん") .with_mark("🥢💙🖤") .build(), - Builder::new().with_mark("☁️🎀").build(), + Builder::new() + .with_name("花ノ木もえ") + .with_mark("☁️🎀").build(), Builder::new().with_mark("📘📗🌼").build(), Builder::new().with_mark("🐈‍⬛💜.*・").build(), ]; @@ -37,7 +39,8 @@ fn main() { ) }; streamer.iter().for_each(|s| printer(s)); - streamer.into_iter().for_each(|s| printer(&s)); +// streamer.into_iter().for_each(|s|#// printer(&s)); +// TODO: streamer.into_iter().for_each(printer); } impl Builder { fn new() -> Self { @@ -83,7 +86,8 @@ fn str_sort_test() { #[test] fn test_loop() { - for i in 2 as i128.. { + //for i in 2 as i128.. { // #[allow(clippy::unnecessary_cast)] + for i in 2_i128.. { println!("{i}"); if i >= i16::MAX.into() { break; @@ -117,7 +121,9 @@ fn test_tuple() { let _tuple_mix_type = ("hello", 5, 'c'); let tuple_one_type = ("hello", "hello", "c"); - let three_tuple = tuple_one_type.clone(); + // https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy + // let three_tuple = tuple_one_type.clone(); + let three_tuple = tuple_one_type; let instance = Tuple3::<&str>::from(three_tuple); println!("{:?}", instance) diff --git a/my-rust-version-hello-world/src/main.rs b/my-rust-version-hello-world/src/main.rs index 2db310e..0e2610b 100644 --- a/my-rust-version-hello-world/src/main.rs +++ b/my-rust-version-hello-world/src/main.rs @@ -1,4 +1,7 @@ - +/** +* My Rust version hello world. +* see: +*/ fn main() { trait MyTrait { fn hello_world(_: T) -> AT; @@ -13,6 +16,7 @@ fn main() { let my_instance = MyStruct("T".to_owned(), "Kumagai".to_owned()); let hello_world_string = >::hello_world(my_instance); + println!("{hello_world_string}"); assert_eq!(hello_world_string, "Hello world, My name is T Kumagai".to_string()); } From c241d99354671155913b0c8c1b51ee9c7e8915b0 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Thu, 18 Jan 2024 18:09:46 +0000 Subject: [PATCH 17/26] /change x to hanndle_names --- iriam-profile/src/main.rs | 63 ++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/iriam-profile/src/main.rs b/iriam-profile/src/main.rs index b2e6eb4..94f477b 100644 --- a/iriam-profile/src/main.rs +++ b/iriam-profile/src/main.rs @@ -1,18 +1,24 @@ type S = LiveStreamer; +#[derive(Debug, Clone)] +enum LiveStreamerPlatform { + Youtube, + IRIAM, + ETC, +} #[derive(Debug, Default, Clone)] struct LiveStreamer { name: Option, mark: Option, - x_name: Option, + handle_names: Option>, + platforms: Option>, } impl LiveStreamer { fn _printer(&self) { println!( - "{}{}{} Liked♡", + "{}{}Liked♡", self.name.clone().unwrap_or_default(), - self.mark.clone().unwrap_or_default(), - self.x_name.clone().unwrap_or_default() + self.mark.clone().unwrap_or_default() ) } } @@ -20,25 +26,54 @@ struct Builder(LiveStreamer); fn main() { let streamer = vec![ Builder::new().with_name("eL(神様)").build(), + Builder::new().with_name("逢坂きゅうり。") + .with_handle_names(vec!["@aisakakyuuuuuri"]) + .build(), Builder::new() - .with_name("はしちゃん") - .with_mark("🥢💙🖤") + .with_name("晴陽かりん") + .with_mark("") + .with_handle_names(vec!["@AmagasaPalapa"]) + .build(), + Builder::new() + .with_name("神園える") + .with_mark("") + .with_handle_names(vec!["@OlangeEru", "@eru_purple"]) + .build(), + Builder::new() + .with_name("キョムノカタマリ") + .with_mark("") + .with_handle_names(vec!["@kyomu_sofione"]) + .build(), + Builder::new() + .with_name("天傘ぱらぱ") + .with_mark("🌩️💛") + .with_handle_names(vec!["@AmagasaPalapa"]) .build(), Builder::new() .with_name("花ノ木もえ") - .with_mark("☁️🎀").build(), - Builder::new().with_mark("📘📗🌼").build(), - Builder::new().with_mark("🐈‍⬛💜.*・").build(), + .with_mark("☁️🎀") + .build(), + Builder::new() + .with_mark("📘📗🌼") + .build(), + Builder::new() + .with_mark("🐈‍⬛💜.*・") + .build(), + Builder::new() + .with_name("はしちゃん") + .with_mark("🥢💙🖤") + .with_handle_names(vec!["@hash_iriam", "@babu_hashi"]) + .build(), ]; let printer = |s: &S| { println!( "{} Liked♡", s.name.clone().unwrap_or_default() + s.mark.clone().unwrap_or_default().as_str() - + s.x_name.clone().unwrap_or_default().as_str() + + s.handle_names.clone().unwrap_or_default().join(",").as_str() ) }; - streamer.iter().for_each(|s| printer(s)); + streamer.iter().for_each(printer); // streamer.into_iter().for_each(|s|#// printer(&s)); // TODO: streamer.into_iter().for_each(printer); } @@ -58,6 +93,12 @@ impl Builder { ..self.0.clone() }) } + fn with_handle_names(&self, handle_names: Vec<&str>) -> Self { + Builder(LiveStreamer { + handle_names: Some(handle_names.iter().map(|str| str.to_string()).collect()), + ..self.0.clone() + }) + } fn build(self) -> LiveStreamer { self.0 } From 9af30df80e4883236ba602f76b5f119ae28b2bfe Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Fri, 19 Jan 2024 03:30:04 +0900 Subject: [PATCH 18/26] remove clippy error. --- iriam-profile/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/iriam-profile/src/main.rs b/iriam-profile/src/main.rs index 94f477b..439bf33 100644 --- a/iriam-profile/src/main.rs +++ b/iriam-profile/src/main.rs @@ -1,17 +1,18 @@ type S = LiveStreamer; +#[allow(dead_code)] #[derive(Debug, Clone)] enum LiveStreamerPlatform { Youtube, - IRIAM, - ETC, + Iriam, + Etc, } #[derive(Debug, Default, Clone)] struct LiveStreamer { name: Option, mark: Option, handle_names: Option>, - platforms: Option>, + // platforms: Option>, } impl LiveStreamer { fn _printer(&self) { From 0572752df2067375b41c9748503893c4d7be2fed Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Fri, 19 Jan 2024 03:34:36 +0900 Subject: [PATCH 19/26] HttpResponse::Ok --- practice_collection/external_crate_use/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice_collection/external_crate_use/src/main.rs b/practice_collection/external_crate_use/src/main.rs index ca63f6f..ce90215 100644 --- a/practice_collection/external_crate_use/src/main.rs +++ b/practice_collection/external_crate_use/src/main.rs @@ -31,7 +31,7 @@ async fn main() -> std::io::Result<()> { web::scope("/v2") .configure(set_configure) ) - .route("/", web::get().to(|| HttpResponse::Ok())) + .route("/", web::get().to(|| HttpResponse::Ok)) }).bind_openssl("127.0.0.1:8082", create_ssl_accepter_builder())? .run() .await From d0100d44120fe63ead1fcf4f0b5f3c0f1161d59d Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Fri, 19 Jan 2024 03:39:03 +0900 Subject: [PATCH 20/26] fix typo. --- practice_collection/external_crate_use/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice_collection/external_crate_use/src/main.rs b/practice_collection/external_crate_use/src/main.rs index ce90215..5a5af79 100644 --- a/practice_collection/external_crate_use/src/main.rs +++ b/practice_collection/external_crate_use/src/main.rs @@ -31,7 +31,7 @@ async fn main() -> std::io::Result<()> { web::scope("/v2") .configure(set_configure) ) - .route("/", web::get().to(|| HttpResponse::Ok)) + .route("/", web::get().to(|| HttpResponse::Ok) }).bind_openssl("127.0.0.1:8082", create_ssl_accepter_builder())? .run() .await From d138be4fbfd39dcef3fbc9a05fe3486dfb445716 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Mon, 22 Jan 2024 20:46:17 +0900 Subject: [PATCH 21/26] before pull --- .gitignore | 1 + Cargo.lock | 2 +- .../src/hash_map_type.rs | 2 +- .../l08_struct/src/playground-1.mongodb.js | 43 +++++++++++++++++++ .../axum_web_framework/Cargo.toml | 10 +++++ .../axum_web_framework/src/main.rs | 17 ++++++++ .../external_crate_use/src/main.rs | 23 ++++++++-- 7 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 examples/l08_struct/src/playground-1.mongodb.js create mode 100644 practice_collection/axum_web_framework/Cargo.toml create mode 100644 practice_collection/axum_web_framework/src/main.rs diff --git a/.gitignore b/.gitignore index d2fd525..d58c624 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ rls/ .vscode practice_collection/external_crate_use/local-key.pem practice_collection/external_crate_use/local.pem +.DS_Store diff --git a/Cargo.lock b/Cargo.lock index a95d389..3e41361 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2602,7 +2602,7 @@ dependencies = [ [[package]] name = "my_rust_version_hello_world" -version = "0.1.0" +version = "0.1.1" [[package]] name = "nanorand" diff --git a/examples/l06_library_data_type/src/hash_map_type.rs b/examples/l06_library_data_type/src/hash_map_type.rs index eaacb43..c350c1f 100644 --- a/examples/l06_library_data_type/src/hash_map_type.rs +++ b/examples/l06_library_data_type/src/hash_map_type.rs @@ -42,7 +42,7 @@ mod test_hash_map_type { for (i, v) in map_x.iter_mut().enumerate() { println!("i:{}, v.0:{}, v.1:{}", i, v.0, v.1); match v { - (k, value) if k == &1 => *value = "changed", + (&1, value) => *value = "changed", _ => {} } } diff --git a/examples/l08_struct/src/playground-1.mongodb.js b/examples/l08_struct/src/playground-1.mongodb.js new file mode 100644 index 0000000..8737dc5 --- /dev/null +++ b/examples/l08_struct/src/playground-1.mongodb.js @@ -0,0 +1,43 @@ +/* global use, db */ +// MongoDB Playground +// To disable this template go to Settings | MongoDB | Use Default Template For Playground. +// Make sure you are connected to enable completions and to be able to run a playground. +// Use Ctrl+Space inside a snippet or a string literal to trigger completions. +// The result of the last command run in a playground is shown on the results panel. +// By default the first 20 documents will be returned with a cursor. +// Use 'console.log()' to print to the debug output. +// For more documentation on playgrounds please refer to +// https://www.mongodb.com/docs/mongodb-vscode/playgrounds/ + +// Select the database to use. +use('mongodbVSCodePlaygroundDB'); + +// Insert a few documents into the sales collection. +db.getCollection('sales').insertMany([ + { 'item': 'abc', 'price': 10, 'quantity': 2, 'date': new Date('2014-03-01T08:00:00Z') }, + { 'item': 'jkl', 'price': 20, 'quantity': 1, 'date': new Date('2014-03-01T09:00:00Z') }, + { 'item': 'xyz', 'price': 5, 'quantity': 10, 'date': new Date('2014-03-15T09:00:00Z') }, + { 'item': 'xyz', 'price': 5, 'quantity': 20, 'date': new Date('2014-04-04T11:21:39.736Z') }, + { 'item': 'abc', 'price': 10, 'quantity': 10, 'date': new Date('2014-04-04T21:23:13.331Z') }, + { 'item': 'def', 'price': 7.5, 'quantity': 5, 'date': new Date('2015-06-04T05:08:13Z') }, + { 'item': 'def', 'price': 7.5, 'quantity': 10, 'date': new Date('2015-09-10T08:43:00Z') }, + { 'item': 'abc', 'price': 10, 'quantity': 5, 'date': new Date('2016-02-06T20:20:13Z') }, +]); + +// Run a find command to view items sold on April 4th, 2014. +const salesOnApril4th = db.getCollection('sales').find({ + date: { $gte: new Date('2014-04-04'), $lt: new Date('2014-04-05') } +}).count(); + +// Print a message to the output window. +console.log(`${salesOnApril4th} sales occurred in 2014.`); + +// Here we run an aggregation and open a cursor to the results. +// Use '.toArray()' to exhaust the cursor to return the whole result set. +// You can use '.hasNext()/.next()' to iterate through the cursor page by page. +db.getCollection('sales').aggregate([ + // Find all of the sales that occurred in 2014. + { $match: { date: { $gte: new Date('2014-01-01'), $lt: new Date('2015-01-01') } } }, + // Group the total sales for each product. + { $group: { _id: '$item', totalSaleAmount: { $sum: { $multiply: [ '$price', '$quantity' ] } } } } +]); diff --git a/practice_collection/axum_web_framework/Cargo.toml b/practice_collection/axum_web_framework/Cargo.toml new file mode 100644 index 0000000..caada0a --- /dev/null +++ b/practice_collection/axum_web_framework/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "axum_web_framework" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +axum = "0.6.20" +tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread"] } diff --git a/practice_collection/axum_web_framework/src/main.rs b/practice_collection/axum_web_framework/src/main.rs new file mode 100644 index 0000000..ed6de6b --- /dev/null +++ b/practice_collection/axum_web_framework/src/main.rs @@ -0,0 +1,17 @@ + +use axum::{routing::get, Router, debug_handler}; + +#[tokio::main] +async fn main() { + let app = Router::new().route("/", get(handler)); + + axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) + .serve(app.into_make_service()) + .await + .unwrap(); +} + +#[debug_handler] +async fn handler() -> &'static str { + "Hello, world" +} \ No newline at end of file diff --git a/practice_collection/external_crate_use/src/main.rs b/practice_collection/external_crate_use/src/main.rs index ca63f6f..028e77f 100644 --- a/practice_collection/external_crate_use/src/main.rs +++ b/practice_collection/external_crate_use/src/main.rs @@ -2,10 +2,11 @@ use actix_web::{ middleware, web::{self, resource, ServiceConfig}, cookie::time::Duration, - App, HttpServer, HttpResponse, Responder, + App, HttpServer, HttpResponse, Responder, Error }; use actix_session::config::BrowserSession; use actix_session::SessionMiddleware; +use actix_session::Session; use actix_session::storage::CookieSessionStore; use openssl::ssl::{SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod}; @@ -17,6 +18,8 @@ async fn main() -> std::io::Result<()> { HttpServer::new(move || { App::new() .wrap(middleware::Logger::default()) + .wrap(middleware::Logger::new("%a %{User-Agent}i")) + .wrap(middleware::DefaultHeaders::new().add(("X-Version", "0.2"))) .wrap( SessionMiddleware::builder( CookieSessionStore::default(), key.clone() @@ -31,7 +34,7 @@ async fn main() -> std::io::Result<()> { web::scope("/v2") .configure(set_configure) ) - .route("/", web::get().to(|| HttpResponse::Ok())) + .service(web::resource("/").to(index)) }).bind_openssl("127.0.0.1:8082", create_ssl_accepter_builder())? .run() .await @@ -43,9 +46,23 @@ fn set_configure(cfg: &mut ServiceConfig) { .route(web::get().to(health)) ); } +async fn index(session: Session) -> Result { + // access session data + if let Some(count) = session.get::("counter")? { + session.insert("counter", count + 1)?; + } else { + session.insert("counter", 1)?; + } + + Ok(HttpResponse::Ok().body(format!( + "Count is {:?}!", + session.get::("counter")?.unwrap() + ))) +} + async fn health() -> impl Responder { - HttpResponse::Ok().content_type(mime::APPLICATION_JSON).json(r#"{"health": "Ok"}"#) + HttpResponse::Ok().content_type(mime::APPLICATION_JSON).body(r#"{"health": "Ok"}"#) } // openssl crate fn create_ssl_accepter_builder() -> SslAcceptorBuilder { From eac356e3c65199c8f3cfc5d9dee9f36a077f2214 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:10:17 +0900 Subject: [PATCH 22/26] merge cargo.lock --- Cargo.lock | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e060a6..fbf88e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -601,6 +601,63 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +dependencies = [ + "async-trait", + "axum-core", + "bitflags 1.3.2", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum_web_framework" +version = "0.1.0" +dependencies = [ + "axum", + "tokio", +] + [[package]] name = "backtrace" version = "0.3.68" @@ -2407,6 +2464,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "md-5" version = "0.10.5" @@ -2538,11 +2601,7 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD -name = "my_rust_version_hello_world" -======= name = "my-rust-version-hello-world" ->>>>>>> d0100d44120fe63ead1fcf4f0b5f3c0f1161d59d version = "0.1.1" [[package]] @@ -3564,6 +3623,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.15" @@ -3792,6 +3857,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -4270,6 +4345,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "system-configuration" version = "0.5.1" @@ -4588,6 +4669,28 @@ dependencies = [ "reqwest", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" From 58cd51a9b72c116f5749b24b9cf1d8a4528e0e60 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:38:54 +0900 Subject: [PATCH 23/26] write readme. --- my_rust_version_hello_world/README.md | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 my_rust_version_hello_world/README.md diff --git a/my_rust_version_hello_world/README.md b/my_rust_version_hello_world/README.md new file mode 100644 index 0000000..17d79ff --- /dev/null +++ b/my_rust_version_hello_world/README.md @@ -0,0 +1,46 @@ +--- +author: friendbeear +updated: 2024-01-22 +last-modified: 2024-01-22 +article-version: 1.1.0 +--- + +# About this prooject + +For beginners of the Rust language, this is an experimental code for Hello World starting here. + +> [GORL] +> The goal is to learn the features of the Rust language in one main.rs. + +Discussion is available at the following link from the official Rust website. + +* [Rust Lang Version Hello World Starting Here.](https://users.rust-lang.org/t/rust-lang-version-hello-world-starting-here/102494) + +## Rust Lang Concept + +* [ ] Operator +* [ ] Constants and Variables +* [ ] Basic data types +* [ ] Control expressions +* [ ] Functions + * [ ] Lifetime +* [x] Struct +* [ ] Enumerated types +* [x] Trait +* [x] Generics +* [ ] Ownership +* [ ] Match operation + +## Features + +### Cargo new option or cargo install binary + +* Case Java + +```sh +cargo new hello-world --from java + # or +rust-hello --generate java hello-world +``` + +To be cootinued. From bc7a70fe167570453472b7ff16f691dbd6a55dde Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:39:16 +0900 Subject: [PATCH 24/26] removed --- practice_collection/axum_web_framework/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/practice_collection/axum_web_framework/src/main.rs b/practice_collection/axum_web_framework/src/main.rs index ed6de6b..87dd9e1 100644 --- a/practice_collection/axum_web_framework/src/main.rs +++ b/practice_collection/axum_web_framework/src/main.rs @@ -1,5 +1,5 @@ -use axum::{routing::get, Router, debug_handler}; +use axum::{routing::get, Router}; #[tokio::main] async fn main() { @@ -11,7 +11,6 @@ async fn main() { .unwrap(); } -#[debug_handler] async fn handler() -> &'static str { "Hello, world" } \ No newline at end of file From c2fbf437bee9e06c08a8068927737c11def923c1 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:59:03 +0900 Subject: [PATCH 25/26] --- examples/l06_library_data_type/src/hash_map_type.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/l06_library_data_type/src/hash_map_type.rs b/examples/l06_library_data_type/src/hash_map_type.rs index 33f6287..c2ed0b0 100644 --- a/examples/l06_library_data_type/src/hash_map_type.rs +++ b/examples/l06_library_data_type/src/hash_map_type.rs @@ -41,10 +41,16 @@ mod test_hash_map_type { for (i, v) in map_x.iter_mut().enumerate() { println!("i:{}, v.0:{}, v.1:{}", i, v.0, v.1); + + // #[allow(clippy::single_match)] + /*/ match v { (&1, value) => *value = "changed", _ => {} } + */ + + if let (&1, value) = v { *value = "changed" } } assert_eq!(map_x.get(&1).unwrap(), &"changed"); assert!(map_x.contains_key(&2)); @@ -53,6 +59,7 @@ mod test_hash_map_type { if let Some(k) = map_x.keys().next() { match k { 1 | 2 | 10 => (), + 20 => (), _ => unreachable!(), } } From df8bbfd67b76b09b8473afd03481e8cc8fd18af0 Mon Sep 17 00:00:00 2001 From: T Kumagai <4956799+friendbear@users.noreply.github.com> Date: Mon, 22 Jan 2024 23:39:19 +0900 Subject: [PATCH 26/26] add CODEOWNERS File. --- .github/CODEOWNERS | 0 my-rust-version-hello-world/README.md | 46 +++++++++++++++++++++++++++ my_rust_version_hello_world/README.md | 46 --------------------------- 3 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 .github/CODEOWNERS delete mode 100644 my_rust_version_hello_world/README.md diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..e69de29 diff --git a/my-rust-version-hello-world/README.md b/my-rust-version-hello-world/README.md index e69de29..17d79ff 100644 --- a/my-rust-version-hello-world/README.md +++ b/my-rust-version-hello-world/README.md @@ -0,0 +1,46 @@ +--- +author: friendbeear +updated: 2024-01-22 +last-modified: 2024-01-22 +article-version: 1.1.0 +--- + +# About this prooject + +For beginners of the Rust language, this is an experimental code for Hello World starting here. + +> [GORL] +> The goal is to learn the features of the Rust language in one main.rs. + +Discussion is available at the following link from the official Rust website. + +* [Rust Lang Version Hello World Starting Here.](https://users.rust-lang.org/t/rust-lang-version-hello-world-starting-here/102494) + +## Rust Lang Concept + +* [ ] Operator +* [ ] Constants and Variables +* [ ] Basic data types +* [ ] Control expressions +* [ ] Functions + * [ ] Lifetime +* [x] Struct +* [ ] Enumerated types +* [x] Trait +* [x] Generics +* [ ] Ownership +* [ ] Match operation + +## Features + +### Cargo new option or cargo install binary + +* Case Java + +```sh +cargo new hello-world --from java + # or +rust-hello --generate java hello-world +``` + +To be cootinued. diff --git a/my_rust_version_hello_world/README.md b/my_rust_version_hello_world/README.md deleted file mode 100644 index 17d79ff..0000000 --- a/my_rust_version_hello_world/README.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -author: friendbeear -updated: 2024-01-22 -last-modified: 2024-01-22 -article-version: 1.1.0 ---- - -# About this prooject - -For beginners of the Rust language, this is an experimental code for Hello World starting here. - -> [GORL] -> The goal is to learn the features of the Rust language in one main.rs. - -Discussion is available at the following link from the official Rust website. - -* [Rust Lang Version Hello World Starting Here.](https://users.rust-lang.org/t/rust-lang-version-hello-world-starting-here/102494) - -## Rust Lang Concept - -* [ ] Operator -* [ ] Constants and Variables -* [ ] Basic data types -* [ ] Control expressions -* [ ] Functions - * [ ] Lifetime -* [x] Struct -* [ ] Enumerated types -* [x] Trait -* [x] Generics -* [ ] Ownership -* [ ] Match operation - -## Features - -### Cargo new option or cargo install binary - -* Case Java - -```sh -cargo new hello-world --from java - # or -rust-hello --generate java hello-world -``` - -To be cootinued.