rust-yaml 0.0.1

A fast, safe YAML 1.2 library for Rust
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# Contributing to rust-yaml

Thank you for your interest in contributing to rust-yaml! We welcome contributions from the community and are pleased to have you aboard.

## Table of Contents

- [Code of Conduct]#code-of-conduct
- [Getting Started]#getting-started
- [Development Setup]#development-setup
- [Making Changes]#making-changes
- [Testing]#testing
- [Code Style]#code-style
- [Submitting Changes]#submitting-changes
- [Security]#security
- [Community]#community

## Code of Conduct

This project and everyone participating in it is governed by our [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to the project maintainers.

## Getting Started

### Prerequisites

- **Rust**: Latest stable version (1.74.0 or higher)
- **Git**: For version control
- **Cargo**: Comes with Rust installation

### Fork and Clone

1. Fork the repository on GitHub
2. Clone your fork locally:

   ```bash
   git clone https://github.com/elioetibr/rust-yaml.git
   cd rust-yaml
   ```

3. Add the upstream repository:

   ```bash
   git remote add upstream https://github.com/elioetibr/rust-yaml.git
   ```

## Development Setup

### Initial Setup

```bash

# Install dependencies and run initial tests
cargo check
cargo test
cargo fmt -- --check
cargo clippy -- -D warnings
```

### Development Environment Setup

Run the setup script to configure git hooks and development tools:

```bash
./scripts/setup-hooks.sh
```

This will:

- Configure git hooks for commit message validation
- Set up conventional commit template
- Install commitlint dependencies (if Node.js available)
- Verify Rust toolchain and components
- Run initial project checks
- Configure helpful git aliases

### Commit Message Format

We use [conventional commits](https://www.conventionalcommits.org/) for consistent commit messages:

```
<type>(<scope>): <description>

[optional body]

[optional footer]
```

**Types:**

- `feat`: New features
- `fix`: Bug fixes
- `docs`: Documentation changes
- `style`: Code style changes (formatting, etc.)
- `refactor`: Code refactoring
- `test`: Adding or updating tests
- `chore`: Build tasks, dependency updates, etc.
- `perf`: Performance improvements
- `ci`: CI/CD changes
- `build`: Build system changes
- `revert`: Reverting previous commits

**Scopes (optional):**
`parser`, `scanner`, `emitter`, `composer`, `constructor`, `lib`, `cli`, `docs`, `tests`, `benches`, `examples`, `ci`, `deps`, `release`

**Examples:**

```bash
feat(parser): add support for complex mapping keys
fix(emitter): resolve string quoting for version numbers
docs: update installation instructions
test(scanner): add edge case tests for deeply nested structures
chore: bump version to 1.1.0 [skip ci]
```

**Special markers:**

- `+semver: major|minor|patch|none` - Control version bumping
- `[skip ci]` or `[ci skip]` - Skip CI builds (for version bumps, docs-only changes)
- `BREAKING CHANGE: description` - Indicate breaking changes

### Development Tools

We recommend installing these additional tools:

```bash

# For code coverage
cargo install cargo-tarpaulin

# For benchmarking
cargo install cargo-criterion

# For security audits
cargo install cargo-audit
```

### Project Structure

```
rust-yaml/
├── src/                    # Source code
│   ├── scanner/           # Token scanning
│   ├── parser/            # Event parsing
│   ├── composer.rs        # Node composition
│   ├── emitter.rs         # YAML output
│   └── lib.rs             # Main library
├── tests/                 # Integration tests
├── benches/              # Performance benchmarks
├── examples/             # Usage examples
└── docs/                 # Documentation
```

## Making Changes

### Branch Naming

Use descriptive branch names:

- `feature/add-streaming-support`
- `fix/merge-keys-bug`
- `docs/update-readme`
- `perf/optimize-scanner`

### Commit Messages

Follow conventional commits format:

```
type(scope): description

[optional body]

[optional footer]
```

Examples:

- `feat(parser): add support for complex keys`
- `fix(scanner): resolve quote style detection bug`
- `docs(readme): update installation instructions`
- `perf(emitter): optimize string allocation`

Types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`

### Code Guidelines

#### General Principles

1. **Safety First**: No `unsafe` code without exceptional justification
2. **Performance**: Zero-copy parsing where possible
3. **Error Handling**: Comprehensive error context with positions
4. **Documentation**: All public APIs must be documented
5. **Testing**: All features must have tests

#### Rust Style

- Follow [Rust API Guidelines]https://rust-lang.github.io/api-guidelines/
- Use `rustfmt` with default settings
- Address all `clippy` warnings
- Prefer explicit error types over `anyhow` in library code
- Use `IndexMap` for preserving key order in mappings

#### YAML Implementation

- Full YAML 1.2 specification compliance
- Round-trip preservation (parse → serialize → parse)
- Secure by default (no code execution)
- Clear error messages with position information

## Testing

### Running Tests

```bash

# Run all tests
cargo test

# Run specific test suite
cargo test test_merge_keys
cargo test integration_tests

# Run with coverage
cargo tarpaulin --out html

# Run benchmarks
cargo bench
```

### Writing Tests

#### Unit Tests

Place unit tests in the same file as the code being tested:

```rust
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_feature_name() {
        // Test implementation
    }
}
```

#### Integration Tests

Place integration tests in the `tests/` directory:

```rust
use rust_yaml::Yaml;

#[test]
fn test_real_world_scenario() {
    let yaml = Yaml::new();
    // Test real-world usage
}
```

#### Test Categories

- **Basic Functionality**: Core parsing and generation
- **YAML 1.2 Compliance**: Specification conformance
- **Advanced Features**: Anchors, merge keys, complex structures
- **Error Handling**: Invalid input and edge cases
- **Performance**: Benchmarks and stress tests
- **Round-trip**: Parse → serialize → parse consistency

### Test Data

For YAML test files, use the `tests/data/` directory:

- Valid YAML files: `tests/data/valid/`
- Invalid YAML files: `tests/data/invalid/`
- Edge cases: `tests/data/edge_cases/`

## Code Style

### Formatting

```bash

# Format code
cargo fmt

# Check formatting
cargo fmt -- --check
```

### Linting

```bash

# Run clippy
cargo clippy -- -D warnings

# Fix clippy suggestions (carefully)
cargo clippy --fix
```

### Documentation

```bash

# Build documentation
cargo doc --open

# Check documentation links
cargo doc --no-deps
```

#### Documentation Guidelines

- Document all public APIs with examples
- Include error conditions in documentation
- Provide usage examples for complex features
- Link to relevant YAML specification sections

## Submitting Changes

### Before Submitting

1. **Rebase** your branch on the latest `main`:

   ```bash
   git fetch upstream
   git rebase upstream/main
   ```

2. **Run the full test suite**:

   ```bash
   cargo test
   cargo clippy -- -D warnings
   cargo fmt -- --check
   ```

3. **Update documentation** if needed
4. **Add tests** for new features
5. **Update CHANGELOG.md** for significant changes

### Pull Request Process

1. **Create a descriptive title**:
   - `Add support for streaming YAML parsing`
   - `Fix memory leak in large document processing`

2. **Write a detailed description**:

   ```markdown
   ## Summary
   Brief description of changes

   ## Changes
   - Specific change 1
   - Specific change 2

   ## Testing
   - [ ] All existing tests pass
   - [ ] Added new tests for feature X
   - [ ] Manual testing completed

   ## Performance Impact
   Description of any performance changes

   ## Breaking Changes
   List any breaking changes
   ```

3. **Link related issues**: Use `Fixes #123` or `Closes #123`

### Review Process

- At least one maintainer review required
- All CI checks must pass
- Address all review feedback
- Keep the PR focused and atomic

## Security

For security vulnerabilities, please see our [Security Policy](SECURITY.md). Do not report security issues through public GitHub issues.

## Community

### Getting Help

- **GitHub Issues**: For bugs and feature requests
- **Discussions**: For questions and general discussion
- **Documentation**: Check the docs first

### Ways to Contribute

#### Code Contributions

- Bug fixes
- New features
- Performance improvements
- Code refactoring

#### Documentation

- API documentation improvements
- Usage examples
- Tutorials and guides
- README enhancements

#### Testing

- Test case improvements
- Performance benchmarks
- YAML specification compliance tests
- Edge case testing

#### Community

- Help answer questions
- Review pull requests
- Participate in discussions
- Share usage examples

## Release Process

(For maintainers)

1. Update version in `Cargo.toml`
2. Update `CHANGELOG.md`
3. Create release PR
4. After merge, tag release: `git tag v1.2.3`
5. Push tags: `git push --tags`
6. GitHub Actions will handle publishing

## Development Tips

### Performance Testing

```bash

# Run benchmarks
cargo bench

# Profile specific benchmark
cargo bench --bench parsing -- --profile-time=10
```

### Memory Testing

```bash

# Check for memory leaks
cargo test --features large-documents
valgrind --tool=memcheck cargo test
```

### Fuzzing

```bash

# Install cargo-fuzz
cargo install cargo-fuzz

# Run fuzzer
cargo fuzz run parse_yaml
```

## Architecture Notes

### Key Components

1. **Scanner** (`src/scanner/`): Tokenizes YAML input
2. **Parser** (`src/parser/`): Generates parsing events
3. **Composer** (`src/composer.rs`): Builds node tree from events
4. **Emitter** (`src/emitter.rs`): Serializes values back to YAML

### Design Principles

- **Streaming**: Process large documents efficiently
- **Zero-copy**: Minimize memory allocations
- **Error Context**: Always provide position information
- **Round-trip**: Preserve formatting and structure

## License

By contributing, you agree that your contributions will be licensed under the MIT License.

---

Thank you for contributing to rust-yaml! 🎉