Skip to content

Latest commit

 

History

History
133 lines (93 loc) · 3.6 KB

README.md

File metadata and controls

133 lines (93 loc) · 3.6 KB

Table of contents

Reference

  • Cheats.rs
    • Easy to read and find cheat sheet for Rust

License

These are some tools to help with the licenses of the libraries the project:

  • cargo-license
    • List licenses of the libraries
  • cargo-lichking
    • Check the compatibility of your project license and the libraries licenses
  • cargo-about
    • Cargo plugin for generating a listing of all of the crates used by a root crate, and the terms under which they are licensed.

Traits

Rust's Built-in Traits, the When, How & Why

Explanation about the built-in traits, nice reminder to review from time to time.

Some of the information is outdated, read with care!

https://llogiq.github.io/2015/07/30/traits.html

VSCode

Extension

Debugging tests

There are cases where the extensions don't work well with the tests, testing with features and workspaces are some of the cases.

For this kind of situation a configuration can be added to launch.json.

Replace the <libname> or remove the filter section for simple cases.

Features may be added to the args section.

For debugging only some specific tests, add the match-filter to the last args section.

{
    "type": "lldb",
    "request": "launch",
    "name": "Debug specific test",
    "cargo": {
        "args": [
            "test",
            "--no-run",
        ],
        "filter": {
            "name": "<libname>",
            "kind": "lib"
        }
    },
    "args": ["<test filter>"],
    "cwd": "${workspaceFolder}"
},

Reference: vadimcn/codelldb#35

Prelude

Here are some starting structures I like to use in a new project.

Result

I like to have a local Result type, it's less to write and easier to refactor.

The ideal is to have also your own local Error type but I usually start with a boxed error and refactor later.

type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

User agent name

Good to set when making network or database queries:

pub const APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));

Common derive

These are some derive types that I need more often then not:

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]

Typed id

Strong typed generic id: typed_id.rs

  • Type safe
  • Implements Deref and other common traits of the underling type
  • Same size as the undeling type
struct User;
type UserId = TypedId<u32, User>;