nsip 0.7.2

NSIP Search API client for nsipsearch.nsip.org/api
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
---
diataxis_type: how-to
---
# Template Configuration Guide

> How to configure your new repository after creating it from the nsip.

This guide covers every customization point in the template, from automatic placeholder replacement to editor and AI assistant configuration.

---

## 1. Placeholder Replacement

After you create a repo from this template, replace all template placeholders
with your project's values (the automated `template-init.yml` workflow is not
included in this repository — replace manually with `sed`/`rg`, or restore a
template-init workflow to automate it).

### Placeholders

| Placeholder | Replaced With | Example |
|-------------|---------------|---------|
| `zircote/nsip` | `your-org/your-repo` (full path) | `acme/my-cli` |
| `zircote/nsip` | `your-org/your_crate` (full path, underscored) | `acme/my_cli` |
| `zircote` | Your GitHub org or username | `acme` |
| `nsip` | Your repo name (hyphenated) | `my-cli` |
| `nsip` | Your crate name (underscored) | `my_cli` |

### How It Would Work (if automated)

This repository does not ship a `template-init.yml` workflow, so replacement is
manual (see below). If you restore such a workflow, the typical flow is:

1. You click **"Use this template"** on GitHub.
2. You push to `main` (or the initial commit triggers the workflow).
3. The workflow detects `name = "nsip"` in `Cargo.toml`.
4. It runs `sed` replacements across all eligible files.
5. It regenerates `Cargo.lock` and commits the result.

### Files to Exclude from Replacement

Skip these paths to avoid corrupting binaries or breaking CI:

- `.git/*` -- Git internals
- `.github/workflows/*` -- CI workflow files
- `*.png`, `*.jpg`, `*.ico` -- Binary image files
- `Cargo.lock` -- Regenerated after replacement

### Manual Replacement

If you need to run replacement manually (e.g., you disabled Actions), use:

```bash
# Set your values
OWNER="your-org"
REPO="your-repo"
CRATE="$(echo "$REPO" | tr '-' '_')"

# Replace in all text files (macOS sed)
find . -type f \
  ! -path './.git/*' \
  ! -path './.github/workflows/*' \
  ! -name '*.png' ! -name '*.jpg' ! -name '*.ico' \
  ! -name 'Cargo.lock' \
  -exec sed -i '' \
    -e "s|zircote/nsip|${OWNER}/${REPO}|g" \
    -e "s|zircote/nsip|${OWNER}/${CRATE}|g" \
    -e "s|zircote|${OWNER}|g" \
    -e "s|nsip|${REPO}|g" \
    -e "s|nsip|${CRATE}|g" \
    {} +

cargo generate-lockfile
```

---

## 2. Cargo.toml Fields to Update

After placeholder replacement runs, review and update these fields in `Cargo.toml`:

| Field | Default | Action |
|-------|---------|--------|
| `name` | `nsip` | Replace manually |
| `version` | `0.1.0` | Update for releases |
| `edition` | `2024` | Leave as-is unless you need an older edition |
| `rust-version` | `1.92` | Update if changing MSRV (see section 6) |
| `authors` | `["Your Name <you@example.com>"]` | Replace with your name and email |
| `description` | `"A Rust template crate..."` | Replace with your crate's description |
| `repository` | `https://github.com/zircote/nsip` | Replace manually |
| `homepage` | `https://github.com/zircote/nsip` | Replace manually |
| `documentation` | `https://docs.rs/nsip` | Replace manually |
| `license` | `MIT` | Change if using a different license |
| `keywords` | `["template", "rust", "example"]` | Replace with up to 5 relevant keywords |
| `categories` | `["development-tools"]` | Replace with applicable [crate categories]https://crates.io/category_slugs |

### Post-Init Checklist

- [ ] Update `authors` with your real name/email
- [ ] Write a meaningful `description`
- [ ] Replace `keywords` with terms relevant to your crate
- [ ] Choose appropriate `categories` from the [crates.io category list]https://crates.io/category_slugs
- [ ] Verify `license` matches your `LICENSE` file
- [ ] Remove the `[[bin]]` section if building a library-only crate

---

## 3. Optional Dependencies

The template `Cargo.toml` includes commented-out dependency blocks. Uncomment what you need:

### Async Runtime (tokio)

```toml
[dependencies]
tokio = { version = "1.0", features = ["full"] }

[dev-dependencies]
tokio-test = "0.4"
```

### Serialization (serde)

```toml
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
```

### Structured Logging (tracing)

```toml
[dependencies]
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
```

### CLI Argument Parsing (clap)

Add `clap` manually -- it is not pre-included in the template:

```toml
[dependencies]
clap = { version = "4", features = ["derive"] }
```

### Steps to Enable

1. Open `Cargo.toml`.
2. Uncomment the relevant lines under `[dependencies]` and `[dev-dependencies]`.
3. Run `cargo check` to verify resolution.
4. If the dependency has a restrictive license, add it to the `allow` list in `deny.toml`.

---

## 4. Feature Flags

The template includes an empty feature flags section in `Cargo.toml`:

```toml
[features]
default = []
# full = ["feature1", "feature2"]
```

### Defining Features

```toml
[features]
default = []
async = ["dep:tokio", "dep:tokio-test"]
serde = ["dep:serde", "dep:serde_json"]
full = ["async", "serde"]
```

### Using Features in Code

Gate modules and items behind feature flags with `cfg` attributes:

```rust
#[cfg(feature = "async")]
pub mod async_client;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[cfg(feature = "serde")]
#[derive(Serialize, Deserialize)]
pub struct Config {
    pub name: String,
}
```

### Building and Testing with Features

```bash
# Build with a specific feature
cargo build --features async

# Build with all features
cargo build --all-features

# Test with no default features
cargo test --no-default-features

# Test with a combination
cargo test --features "async,serde"
```

### CI Consideration

The template CI runs `cargo clippy --all-targets --all-features` and `cargo test --all-features` by default. If your features are mutually exclusive, update the CI workflow matrix to test each combination separately.

---

## 5. Lint Configuration

Three configuration files control code quality rules. Adjust them to match your project's requirements.

### clippy.toml

Controls Clippy lint behavior and thresholds.

| Setting | Default | Purpose |
|---------|---------|---------|
| `msrv` | `"1.92"` | Minimum Rust version for lint suggestions |
| `cognitive-complexity-threshold` | `25` | Max cognitive complexity per function |
| `too-many-lines-threshold` | `100` | Max lines per function |
| `too-many-arguments-threshold` | `7` | Max function parameters |
| `excessive-nesting-threshold` | `4` | Max nesting depth |
| `max-struct-bools` | `3` | Max bool fields in a struct |
| `allow-unwrap-in-tests` | `true` | Permit `.unwrap()` in test code |
| `allow-expect-in-tests` | `true` | Permit `.expect()` in test code |

### rustfmt.toml

Controls code formatting rules.

| Setting | Default | Purpose |
|---------|---------|---------|
| `edition` | `"2024"` | Parsing edition |
| `max_width` | `100` | Maximum line width |
| `tab_spaces` | `4` | Spaces per indentation level |
| `imports_granularity` | `"Crate"` | How imports are grouped |
| `group_imports` | `"StdExternalCrate"` | Import section ordering |
| `wrap_comments` | `true` | Wrap long comments |
| `format_code_in_doc_comments` | `true` | Format code blocks in doc comments |
| `trailing_comma` | `"Vertical"` | Add trailing commas in multi-line contexts |

### deny.toml

Controls dependency auditing via `cargo-deny`.

| Section | What to Customize |
|---------|-------------------|
| `[advisories]` | Add crate IDs to `ignore` to suppress known advisories |
| `[licenses].allow` | Add SPDX identifiers for licenses your project permits |
| `[bans].deny` | Add crates you want to forbid (e.g., `openssl`) |
| `[bans].skip` | Allow specific duplicate dependency versions |
| `[sources].allow-git` | Add Git repository URLs for non-crates.io dependencies |

### Cargo.toml Lint Table

The `[lints.clippy]` section in `Cargo.toml` sets lint levels. Key denied lints:

```toml
unwrap_used = "deny"      # Use Result instead
expect_used = "deny"       # Use Result instead
panic = "deny"             # No panics in library code
todo = "deny"              # No incomplete code
unimplemented = "deny"     # No stubs
dbg_macro = "deny"         # No debug macros
print_stdout = "deny"      # Use tracing/log instead
print_stderr = "deny"      # Use tracing/log instead
```

To relax a lint for your project, change `"deny"` to `"warn"` or `"allow"`.

---

## 6. MSRV Policy

The current minimum supported Rust version is **1.92**.

### Changing the MSRV

Update all three locations to keep them in sync:

| File | Field | Example |
|------|-------|---------|
| `Cargo.toml` | `rust-version` | `rust-version = "1.85"` |
| `clippy.toml` | `msrv` | `msrv = "1.85"` |
| CI workflow matrix | `rust:` versions | Add your MSRV to the test matrix |

### Verification

```bash
# Install a specific toolchain to verify MSRV
rustup install 1.85
cargo +1.85 check
cargo +1.85 test
```

---

## 7. Editor Configuration

### .editorconfig

Cross-editor defaults applied automatically by editors that support [EditorConfig](https://editorconfig.org):

| Setting | Value | Scope |
|---------|-------|-------|
| `indent_style` | `space` | All files |
| `indent_size` | `4` | Default (2 for YAML/JSON) |
| `max_line_length` | `100` | All files |
| `end_of_line` | `lf` | All files |
| `charset` | `utf-8` | All files |
| `insert_final_newline` | `true` | All files |
| `trim_trailing_whitespace` | `true` | All files (except Markdown) |

### .vscode/settings.json

VS Code workspace settings:

- `rust-analyzer.check.command` set to `clippy` (lints on save)
- `rust-analyzer.check.extraArgs` includes `--all-targets --all-features`
- `editor.formatOnSave` enabled
- `editor.rulers` set to `[100]` to show the line-length guide
- `target/` directory excluded from file explorer

### .vscode/extensions.json

Recommended extensions (VS Code prompts to install these):

| Extension | Purpose |
|-----------|---------|
| `rust-lang.rust-analyzer` | Rust language server |
| `tamasfe.even-better-toml` | TOML syntax and validation |
| `serayuzgur.crates` | Inline crate version info |
| `usernamehw.errorlens` | Inline error/warning display |
| `vadimcn.vscode-lldb` | Native debugger |

### .devcontainer/

GitHub Codespaces and VS Code Dev Container configuration:

- **Base image:** `mcr.microsoft.com/devcontainers/rust:1-bookworm`
- **Post-create command:** installs `cargo-deny`, `cargo-tarpaulin`, `cargo-watch`, and runs `cargo fetch`
- **VS Code settings and extensions** mirror the workspace configuration above

To customize the dev container, edit `.devcontainer/devcontainer.json`. Common changes:

- Add system packages via `"features"` or a custom `Dockerfile`
- Add environment variables with `"containerEnv"`
- Forward ports with `"forwardPorts"`
- Install additional cargo tools in `"postCreateCommand"`

---

## 8. AI Assistant Configuration

The template includes configuration files for multiple AI coding assistants.

### CLAUDE.md

Instructions for [Claude Code](https://docs.anthropic.com/en/docs/claude-code). Located at the repo root.

- Build commands, project structure, and code style rules
- Error handling patterns and documentation requirements
- Testing conventions and CI/CD pipeline details

### AGENTS.md

Instructions for AI coding agents (read by [GitHub Copilot coding agent](https://docs.github.com/en/copilot/using-github-copilot/using-copilot-coding-agent) and compatible systems). Located at the repo root.

- Read by AI coding agents when they work on issues and PRs
- Shares the same project conventions as `CLAUDE.md`

### .github/copilot-instructions.md

Instructions for [GitHub Copilot Chat](https://docs.github.com/en/copilot/customizing-copilot/adding-custom-instructions-for-github-copilot). Loaded automatically in Copilot Chat conversations.

- Provides project-wide context for inline suggestions and chat responses

### .github/instructions/

[Path-specific instruction files](https://docs.github.com/en/copilot/customizing-copilot/adding-custom-instructions-for-github-copilot) applied when Copilot works on matching file paths:

| File | Scope |
|------|-------|
| `rust-code.instructions.md` | Rust source files (`crates/**/*.rs`) |
| `tests.instructions.md` | Test files (`tests/**/*.rs`) |

### .github/prompts/

[Reusable prompt files](https://docs.github.com/en/copilot/customizing-copilot/adding-custom-instructions-for-github-copilot) for common development tasks:

| Prompt | Purpose |
|--------|---------|
| `new-module.prompt.md` | Scaffold a new Rust module |
| `fix-clippy.prompt.md` | Fix Clippy lint warnings |
| `add-error-variant.prompt.md` | Add a new error type variant |
| `write-tests.prompt.md` | Generate tests for existing code |

### Customizing AI Instructions

- Edit `CLAUDE.md` and `AGENTS.md` at the repo root to update project-wide conventions.
- Add new `.instructions.md` files under `.github/instructions/` for path-specific rules.
- Add new `.prompt.md` files under `.github/prompts/` for reusable task prompts.
- All AI instruction files are regular Markdown -- placeholder replacement applies to them automatically.