Last active
February 23, 2021 21:10
-
-
Save s-newman/5439660d5f0cc74595baaf16d23db4ae to your computer and use it in GitHub Desktop.
A starter `lib.rs` for rust libraries that enables lots of clippy lints and provides some macros to make simple unit tests faster to write.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![warn( | |
clippy::all, | |
clippy::pedantic, | |
// clippy::cargo, | |
// TODO: uncomment above | |
// Restriction lints | |
clippy::as_conversions, | |
clippy::dbg_macro, | |
clippy::decimal_literal_representation, | |
clippy::else_if_without_else, | |
clippy::exit, | |
clippy::expect_used, | |
clippy::filetype_is_file, | |
clippy::float_cmp_const, | |
clippy::get_unwrap, | |
clippy::lossy_float_literal, | |
clippy::mem_forget, | |
clippy::multiple_inherent_impl, | |
clippy::rest_pat_in_fully_bound_structs, | |
clippy::unneeded_field_pattern, | |
clippy::unreachable, | |
clippy::unwrap_in_result, | |
clippy::use_debug, | |
clippy::verbose_file_reads, | |
clippy::wrong_pub_self_convention, | |
// TODO: uncomment below | |
/* | |
// These lints are useful to enable in your final code, but can be annoyingly noisy during | |
// development. Just make sure to turn them on when you're done! | |
clippy::missing_docs_in_private_items, | |
clippy::panic_in_result_fn, | |
clippy::todo, | |
clippy::unimplemented, | |
*/ | |
)] | |
// Tagging everything with #[must_use] can be a little annoying | |
#![allow(clippy::must_use_candidate)] | |
// Behavior that triggers this lint can actually be useful to enable better forward compatibility | |
#![allow(clippy::match_wildcard_for_single_variants)] | |
/* Example: | |
_test_eq { | |
addition: (1 + 1, 2), | |
trimming: ("hello, world".trim_start_matches("hello,"), " world"), | |
} | |
*/ | |
#[macro_use] | |
macro_rules! _test_eq { | |
($($name:ident: $value:expr,)*) => { | |
$( | |
#[test] | |
fn $name() { | |
let (input, expected) = $value; | |
assert_eq!(input, expected); | |
} | |
)* | |
} | |
} | |
/* Example: | |
let x: Option<&str> = None; | |
_test_err { | |
just_an_error: (Err("a basic error")), | |
option_none_ok_or: (x.ok_or(0)) | |
} | |
*/ | |
#[macro_use] | |
macro_rules! _test_err { | |
($($name:ident: $value:expr,)*) => { | |
$( | |
#[test] | |
fn $name() { | |
assert!($value.is_err()); | |
} | |
)* | |
} | |
} | |
// This contains all possible derives included in the standard library | |
// #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | |
// This is a basic starter that will work for the vast majority of cases | |
// #[derive(Clone, Debug)] | |
/*** Submodules ***/ | |
// mod foo; | |
// pub mod bar; | |
/*** Re-imports ***/ | |
// use foo::Foo; | |
// pub use bar::Bar; | |
/*** Top-level implementations ***/ | |
// use std::fs::File | |
// type Baz = File; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment