Skip to content

Conversation

@RAprogramm
Copy link
Owner

Closes #5

Changes

Added four comprehensive examples demonstrating practical usage of cstring-array:

examples/basic.rs

  • Basic CStringArray creation from Vec
  • Accessing array properties (length, emptiness, pointer)
  • Safe iteration over elements
  • Individual element access
  • Demonstrates automatic memory cleanup

examples/command_line.rs

  • Real-world command-line argument handling
  • FFI interoperability with C functions
  • Simulates passing argv to C code
  • Command parsing demonstration
  • Shows proper argc/argv pattern

examples/env_vars.rs

  • Creating arrays from environment variables
  • KEY=VALUE formatting for C-style environment
  • Filtering and transforming data
  • Searching for specific variables
  • Demonstrates use case for execve() and similar functions

examples/zero_copy.rs

  • Zero-copy construction from Vec
  • Performance comparison with regular construction
  • When to use from_cstrings() vs new()
  • Large dataset demonstration (1000 elements)
  • Memory efficiency explanation

Features

  • All examples compile without warnings
  • Executable via cargo run --example
  • Comprehensive inline documentation
  • Real-world use cases
  • REUSE 3.3 compliant
  • Follow project code style guidelines

Testing

  • All examples build successfully
  • basic.rs runs and produces expected output
  • command_line.rs handles arguments correctly
  • env_vars.rs processes environment variables
  • zero_copy.rs demonstrates performance benefits
  • REUSE compliance verified

Documentation

Each example includes:

  • File-level documentation explaining purpose
  • Inline comments for clarity
  • Usage instructions
  • Real-world application scenarios

Run examples with:

cargo run --example basic
cargo run --example command_line -- --verbose file.txt
cargo run --example env_vars
cargo run --example zero_copy

- Add examples/basic.rs - basic CStringArray usage
- Add examples/command_line.rs - FFI with command-line args
- Add examples/env_vars.rs - environment variables handling
- Add examples/zero_copy.rs - zero-copy construction demo
- Update REUSE.toml to include examples directory

Examples demonstrate:
- Creating arrays from Vec<String>
- Zero-copy construction from Vec<CString>
- FFI interoperability with C functions
- Safe iteration and element access
- Real-world use cases (CLI args, env vars)
- Automatic memory management
- Performance considerations

All examples:
- Compile without warnings
- Run successfully
- Include comprehensive comments
- Follow REUSE 3.3 specification
- Demonstrate best practices

Usage:
  cargo run --example basic
  cargo run --example command_line -- arg1 arg2
  cargo run --example env_vars
  cargo run --example zero_copy
@RAprogramm RAprogramm merged commit d57fe7f into main Oct 19, 2025
1 check passed
@RAprogramm RAprogramm deleted the 5 branch October 19, 2025 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add practical usage examples

1 participant