Skip to content

Latest commit

 

History

History
252 lines (247 loc) · 10.1 KB

rust-guru-notes.md

File metadata and controls

252 lines (247 loc) · 10.1 KB
  • use Trait as _ by default

    • Most traits don't need to be named
    • This could be a lint
  • cargo +nightly test -Z direct-minimal-versions

    • seems useful
  • cargo rustc --crate-type=xxx

  • Unnamed trait imports with _

  • How to rebase around Cargo.lock conflicts

  • Option::flatten let src_time = src_path.metadata() .ok().map(|m| m.modified().ok()).flatten();

  • PhantomData

  • using cfg_attr for conditional lines of docs

    //! You can serialize types in a similar fashion: //! #![cfg_attr(not(feature = "display"), doc = " ignore")] #![cfg_attr(feature = "display", doc = " ")] //! use serde::Serialize;

  • getting async blocks to typecheck ?
    • Ok::<_, anyhow::Error>(())
    • for async test cases
  • test runner has its own flags
    • --nocapture
  • rustc won't attempt to link other crates if they are not referenced
    • this can cause huge confusion of those other crates only contain c symbols since rustc won't pass them to the linker and they'll just disappear
  • Sealed trait pattern
  • cargo aliases
  • Should I end a function with a passthrough call or with ?; Ok(())
  • Following crates.io / docs.rs to GitHUb etc.
  • -- --test-threads=1 will print names of test cases before they hard-crash
  • don't use unchecked functions just because you "know" the invariant holds (i.e. from_utf8_unchecked)
  • remove_dir_all crate
  • Arc::make_mut for copy-on-write
  • {String}.as_ref().map(Borrow::borrow) -> &str
  • count complete source lines with cargo vendor + tokei
  • criterion
  • println!("{:#?}", ...);
  • CI building with --locked when Cargo.toml is checked in
  • dbg!
  • getset crate
  • cargo-local-registry
  • Struct { no, name, stuttering }
  • cloned() tricks
  • turn default features off for deps if possible
    • otherwise they can't be turned off by other crates
    • default features considered harmful
  • cargo search
  • AsRef vs Borrow
  • iterator cloned() vs borrowed()
  • Path::display()
  • don't jump to lifetimes
    • even graydon doesn't
  • drop impacts API - re serde Value recursion