From 6c79aef18cd3b13e380098e982da22cb36caab0e Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 27 Oct 2023 11:37:26 -0500 Subject: [PATCH] Clippy super strict --- flake.nix | 1 + readme.md | 5 ++++- src/main.rs | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index a289545..4faf3e9 100644 --- a/flake.nix +++ b/flake.nix @@ -24,6 +24,7 @@ formatter = nixpkgs.legacyPackages.${system}.alejandra; checks = { inherit (self.packages.${system}) default; + # TODO: clippy }; devShell = with pkgs; mkShell { diff --git a/readme.md b/readme.md index 91a3f7d..e245992 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,10 @@ # Learn Rust in a Month of Lunches Bought [this book][book] and this code contains my musings and other stuff that -I write as I work through it. +I write as I work through it. I'm already familiar with a few aspects of Rust +and maintain a widely-deployed Rust project at work, so will be focusing on +stuff new and/or interesting to me and mostly ignoring anything that I believe +I'm familiar with -- correctly or not. Enjoy! diff --git a/src/main.rs b/src/main.rs index 1621a54..45ba317 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,43 @@ +#![warn( + clippy::all, + clippy::style, + clippy::absolute_paths, + clippy::pedantic, + clippy::nursery, + // clippy::cargo +)] + +//! my code and notes from the book "Learn Rust in a Month of Lunches" + /// a doc comment - use `cargo doc --open` to see it? fn main() { + // ch 1 let c: char = '\u{D1EA}'; - let bytes = b"yoyoyo"; - let me = "meeeeeeeeeeeeeeeeeeeeeeeeeee"; println!("Hello, world! {c}"); + + // ch 2 + let bytes = b"yoyoyo"; println!("Hello, bytes! {bytes:?}"); + + let me = "meeeeeeeeeeeeeeeeeeeeeeeeeee"; println!("Hello, {me: <4.12}, meet the real {me}."); + + // ch 3 + let children = 5; + let married = true; + + // match guards + match (children, married) { + (children, married) if !married => { + println!("Not married with {children} kids"); + } + (children, married) if children == 0 && married => { + println!("Married but no children"); + } + _ => { + println!("Married? {married}. Number of children: {children}."); + } + } } // if I were to write a webapp, I would like to avoid postgres