We appreciate your interest in contributing to MsgTrans! This document outlines the guidelines and processes for contributing to this modern multi-protocol communication framework.
MsgTrans aims to make multi-protocol communication simple, efficient, and reliable. Our core principles are:
- Simplicity: Elegant APIs that hide complexity
- Performance: Lock-free, zero-copy, high-throughput design
- Reliability: Type-safe, well-tested, production-ready code
- Extensibility: Clean architecture supporting custom protocols
- Developer Experience: Excellent documentation and examples
- Rust: 1.80+ (stable toolchain)
- Git: For version control
- IDE: VSCode with rust-analyzer or similar
-
Fork and Clone
git clone https://github.com/zoujiaqing/msgtrans.git cd msgtrans-rust -
Install Dependencies
cargo build
-
Run Tests
cargo test --all-features -
Run Examples
cargo run --example echo_server cargo run --example echo_client_tcp
- Use GitHub Issues with the "bug" label
- Include minimal reproduction steps
- Provide environment details (OS, Rust version)
- Include relevant logs and error messages
- Use GitHub Issues with the "enhancement" label
- Explain the use case and problem it solves
- Consider backward compatibility
- Discuss API design implications
- README improvements
- API documentation (rustdoc)
- Examples and tutorials
- Architecture documentation
- Bug fixes
- Performance improvements
- New protocol adapters
- Testing improvements
Language Standards
- All code, comments, and documentation must be in English
- No emoji symbols in source code (use text tags like
[PERF]if needed) - No "Phase" keywords or development evolution comments
- Professional, technical language throughout
Rust Standards
- Follow standard Rust conventions (
cargo fmt) - Use
cargo clippyfor linting - Prefer explicit types when it improves clarity
- Use meaningful variable and function names
Architecture Patterns
- Builder pattern for configuration
- Event-driven design
- Protocol-agnostic abstractions
- Zero-copy where possible
src/
├── lib.rs # Public API exports
├── error.rs # Error types and handling
├── event.rs # Event system definitions
├── packet.rs # Packet serialization
├── connection.rs # Connection abstractions
├── transport/ # Transport layer
│ ├── mod.rs
│ ├── server.rs
│ ├── client.rs
│ └── ...
├── adapters/ # Protocol adapters
│ ├── tcp.rs
│ ├── websocket.rs
│ ├── quic.rs
│ └── ...
└── protocol/ # Protocol configurations
└── ...
- Lock-free: Use atomic operations and lock-free data structures
- Zero-copy: Minimize data copying with
Arc<[u8]>and similar - Async-first: All I/O must be asynchronous
- Memory efficient: Reuse buffers, avoid unnecessary allocations
Unit Tests
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_tcp_connection_lifecycle() {
// Test implementation
}
}Integration Tests
- Place in
tests/directory - Test real protocol scenarios
- Include performance benchmarks
Documentation Tests
- All public APIs must have doc tests
- Examples should be runnable
- Include error handling examples
<type>(<scope>): <description>
[optional body]
[optional footer]
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, etc.)refactor: Code refactoringperf: Performance improvementstest: Adding or updating testschore: Build process or auxiliary tool changes
Examples:
feat(transport): add QUIC protocol adapter
Implement QUIC protocol support with:
- Connection establishment and management
- Stream multiplexing
- TLS 1.3 integration
Closes #123
fix(tcp): resolve connection leak in error handling
Fix memory leak when TCP connections fail during handshake.
Ensure proper cleanup of file descriptors and allocated buffers.
Fixes #456
-
Create Feature Branch
git checkout -b feature/awesome-new-feature
-
Write Tests
- Unit tests for new functionality
- Integration tests for complex features
- Benchmark tests for performance claims
-
Update Documentation
- Rustdoc for public APIs
- README if adding new features
- Examples demonstrating usage
-
Run Quality Checks
cargo fmt cargo clippy --all-targets --all-features cargo test --all-features cargo doc --no-deps
## Summary
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Performance improvement
- [ ] Documentation update
- [ ] Refactoring
## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
- [ ] Performance benchmarks (if applicable)
## Documentation
- [ ] Code is documented
- [ ] Examples updated
- [ ] README updated (if needed)
## Checklist
- [ ] Code follows project standards
- [ ] All English language used
- [ ] No emoji symbols in source code
- [ ] Commits follow conventional format
- [ ] Tests added for new functionality- Automated Checks: CI must pass
- Code Review: At least one maintainer approval
- Testing: Comprehensive test coverage
- Documentation: Complete API documentation
# All tests
cargo test --all-features
# Specific module
cargo test transport::tests
# Integration tests
cargo test --test integration
# With output
cargo test -- --nocapture# Benchmarks
cargo bench
# Memory profiling
cargo run --example memory_profile# Install coverage tool
cargo install cargo-tarpaulin
# Generate coverage report
cargo tarpaulin --all-features --out Html/// Establishes a connection using the specified protocol configuration.
///
/// This method performs the complete connection lifecycle including:
/// - Protocol negotiation
/// - Authentication (if required)
/// - Channel establishment
///
/// # Arguments
///
/// * `config` - Protocol-specific configuration
///
/// # Returns
///
/// Returns a `Result` containing the established connection or an error.
///
/// # Errors
///
/// This method will return an error if:
/// - Network connectivity fails
/// - Protocol negotiation fails
/// - Authentication is rejected
///
/// # Examples
///
/// ```rust
/// use msgtrans::{protocol::TcpClientConfig, tokio};
///
/// let config = TcpClientConfig::new("127.0.0.1:8080")?;
/// let client = TransportClientBuilder::new()
/// .with_protocol(config)
/// .build()
/// .await?;
/// ```
pub async fn connect(&mut self) -> Result<(), TransportError> {
// Implementation
}- Complete: Runnable examples
- Practical: Real-world use cases
- Documented: Inline comments explaining key concepts
- Error Handling: Proper error management
-
Create Protocol Adapter
pub struct MyProtocolAdapter { // Implementation } #[async_trait] impl ProtocolAdapter for MyProtocolAdapter { // Required methods }
-
Configuration Types
pub struct MyProtocolServerConfig { // Configuration fields } impl ServerConfig for MyProtocolServerConfig { // Implementation }
-
Error Handling
- Protocol-specific error types
- Proper error propagation
- Graceful degradation
-
Testing Suite
- Unit tests for adapter logic
- Integration tests with real connections
- Performance benchmarks
-
Documentation
- API documentation
- Usage examples
- Protocol-specific guides
- Respectful: Treat all contributors with respect
- Inclusive: Welcome diverse perspectives and backgrounds
- Constructive: Provide helpful, actionable feedback
- Professional: Maintain professional communication
- Collaborative: Work together toward common goals
- Harassment or discrimination
- Trolling or inflammatory comments
- Personal attacks
- Spam or off-topic content
- Violation of privacy
Issues can be reported to the maintainers. All reports will be handled confidentially and appropriately.
- GitHub Issues: Bug reports and feature requests
- GitHub Discussions: General questions and community discussion
- Email: Direct contact with maintainers
- Documentation: Check rustdoc and README first
- Examples: Review example code in
examples/ - Tests: Look at existing tests for patterns
We follow Semantic Versioning:
- MAJOR: Breaking API changes
- MINOR: New features (backward compatible)
- PATCH: Bug fixes (backward compatible)
- All tests pass
- Documentation updated
- CHANGELOG.md updated
- Version bumped in Cargo.toml
- Git tag created
- Published to crates.io
Contributors are recognized in several ways:
- Git history: All contributions are preserved
- Release notes: Major contributions highlighted
- README: Core contributors listed
Thank you for contributing to MsgTrans! 🚀
Questions? Open an issue or start a discussion. We're here to help!