---
# System prepended metadata

title: Rust Tips for Google Hash Code

---

# Rust Tips for Google Hash Code

1. Stick to the basic language functions.
    * Stick to basic variable types.
        * u8, u16, u32, u64, f64.
        * HashMap
        * Vec
        * String
        * Struct (for data representation)
    * Avoid traits and closures unless it really makes sense.
    * Know what `#[derive(Clone, Debug)]` means for a struct.
2. Familiarize with all essential libraries ahead of time.
3. Use a benchmark timer in your code. If your process is extremely long running, you need to be able to identify this quickly rather than waiting for it.
4. Always compile for release! Performance is much higher than debug.
5. Install and use `cargo watch`. On every save it will recompile and run.
6. Iterating code quickly is important. Copying a folder and renaming works well, but always make a note somewhere on what the version you're working on does different. You will end up with many versions very quickly.
7. Consider suppressing unnecessary warnings, such as unused libraries. You need to identify real errors quickly, and these warnings will not matter during competition.
8. Write and familiarize with as much boilerplate code as you can beforehand. This includes things like:
    * Reading command line arguments.
    * Parsing data files.
    * Writing output files.
    * Timing iterations.

---
## Helpful Links

###### Rust Type Conversion → https://carols10cents.github.io/rust-conversion-reference/
###### Rust CheatSheet → https://cheats.rs/
###### Rust Type Conversion → https://carols10cents.github.io/rust-conversion-reference/
###### Rust Type Conversion → https://carols10cents.github.io/rust-conversion-reference/
---

## How to

### 3. Code benchmark

Moved Code To → https://hackmd.io/@ghc2021/S1BHUMJfu

### 4. Release builds

Simply:
```
cargo run --release
```

If you need to execute cargo run in other directory use `--manifest-path`:
```
cargo run --manifest-path code/Cargo.toml --release
```

### 5. Syntax checking

Alternative approach if you use VScode, install: https://github.com/rust-analyzer/rust-analyzer

### 7. Suppress warnings

Moved Code To → https://hackmd.io/@ghc2021/S1BHUMJfu

### 8. Boilerplate

Moved Code To → https://hackmd.io/@ghc2021/S1BHUMJfu

##### VSCode configurations for debug and launch

For project structure:

```
ROOT
 - .vscode
 
 - code
 -- src
 -- Cargo.toml
 
 - data
 -- input
 --- a_example.txt
```

.vscode/launch.json:
```
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Build & Debug",
            "args": [], // you can specify command line options here like "0" etc.
            "program": "${workspaceFolder}/code/target/debug/REPLACE_WITH_PACKAGE_NAME",
            "cwd": "${workspaceFolder}",
            "stopOnEntry": false,
            "sourceLanguages": [
              "rust"
            ],
            "preLaunchTask": "build",
          },
    ]
}
```

.vscode/tasks.json:
```
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "cargo build",
            "options": {
              "cwd": "${workspaceFolder}/code"
            },
            "group": {
              "kind": "build",
              "isDefault": true
            },
            "problemMatcher": []
          },
    ]
}
```