Taitank Rust is a Rust implementation of Taitank, a cross-platform lightweight Flexbox layout engine.
- ✅ Complete Flexbox Support - Supports all Flexbox layout properties, fully compatible with the C++ version
- ✅ High Performance - Optimized layout algorithm with layout caching, performance comparable to the C++ version
- ✅ Memory Safe - Rust's ownership system ensures memory safety without manual memory management
- ✅ Type Safe - Strong type system reduces runtime errors and catches issues at compile time
- ✅ API Compatible - Compatible with the C++ version API, easy to migrate
- ✅ Test Coverage - Complete unit test coverage (30+ test files, 280+ test cases)
- ✅ Multi-platform Support - Supports macOS, Linux, Windows, Android, iOS
- ✅ Comprehensive Documentation - Complete API documentation and usage examples
Add the dependency to your Cargo.toml:
[dependencies]
taitank-rs = "0.1.2"Or use from Git repository:
[dependencies]
taitank-rs = { git = "https://github.com/rustq/taitank-rs.git" }use taitank::*;
// Create a root node
let root = node_create();
set_width(&root, 500.0);
set_height(&root, 300.0);
set_flex_direction(&root, FlexDirection::Row);
set_padding(&root, CSSDirection::All, 20.0);
// Create a child node
let child1 = node_create();
set_width(&child1, 100.0);
set_height(&child1, 100.0);
set_margin(&child1, CSSDirection::Right, 10.0);
insert_child(&root, child1.clone(), 0);
// Create a child node with flex
let child2 = node_create();
set_flex(&child2, 1.0); // flex: 1 to automatically fill remaining space
set_height(&child2, 100.0);
insert_child(&root, child2.clone(), 0);
// Perform layout calculation
do_layout(&root, VALUE_UNDEFINED, VALUE_UNDEFINED, TaitankDirection::Ltr, None);
// Get layout results
println!("Root: {}x{}", get_width(&root), get_height(&root));
println!("Child1: {}x{} at ({}, {})",
get_width(&child1), get_height(&child1),
get_left(&child1), get_top(&child1));
println!("Child2: {}x{} at ({}, {})",
get_width(&child2), get_height(&child2),
get_left(&child2), get_top(&child2));The project includes multiple examples demonstrating different use cases:
# Run basic example
cargo run --example basic
# Run complex layout example
cargo run --example complex
# Run absolute positioning example
cargo run --example absolute_positionSee the examples/ directory for more example code.
Run all tests:
cargo testRun a specific test:
cargo test align_self_testRun tests with output:
cargo test -- --nocaptureRun performance benchmarks using Criterion:
cargo bench --bench benchmarkBenchmarks include:
- Stack with flex - Stacked flex layout (~4.05 µs)
- Align stretch in undefined axis - Stretch alignment in undefined axis (~4.04 µs)
- Nested flex - Nested flex layout (~60.5 µs)
- Huge nested layout - Large nested layout (~3.41 ms)
- Huge nested layout (no style) - Large nested layout without styles (~8.06 ms)
Performance reports are generated in the target/criterion/ directory with detailed performance analysis.
Generate and view API documentation:
cargo doc --openOnline documentation: https://docs.rs/taitank-rs
Use directly as a Rust library, supports the following platforms:
- ✅ macOS (x86_64, arm64)
- ✅ Linux (x86_64, arm64)
- ✅ Windows (x86_64, MSVC/GNU)
- ✅ Android (arm64-v8a, armeabi-v7a, x86, x86_64)
- ✅ iOS (arm64, x86_64 simulator)
taitank-rust/
├── src/ # Source code
│ ├── api.rs # Public API
│ ├── node.rs # Core node implementation
│ ├── style.rs # Style management
│ ├── flex.rs # Flexbox types and enums
│ ├── flexline.rs # FlexLine implementation
│ ├── cache.rs # Layout caching
│ ├── config.rs # Configuration management
│ ├── util.rs # Utility functions
│ └── lib.rs # Library entry point
├── tests/ # Unit tests (30+ test files)
├── examples/ # Example code
│ ├── basic.rs # Basic usage example
│ ├── complex.rs # Complex layout example
│ └── absolute_position.rs # Absolute positioning example
├── benches/ # Performance benchmarks
│ └── benchmark.rs # Criterion benchmarks
├── .cargo/ # Cargo configuration
│ └── config.toml # Cross-compilation configuration
├── .github/ # GitHub configuration
│ └── workflows/ # CI/CD workflows
├── build.sh # Build script
├── Cargo.toml # Project configuration
├── README.md # This file
├── README_ZH.md # Chinese version
├── PLATFORMS.md # Platform build guide
└── INTEGRATION.md # Integration guide
set_width()/get_width()- Widthset_height()/get_height()- Heightset_min_width()/set_min_height()- Minimum dimensionsset_max_width()/set_max_height()- Maximum dimensions
set_flex()- Flex shorthandset_flex_grow()- Flex-growset_flex_shrink()- Flex-shrinkset_flex_basis()- Flex-basisset_flex_direction()- Flex-directionset_flex_wrap()- Flex-wrap
set_justify_content()- Justify-contentset_align_items()- Align-itemsset_align_content()- Align-contentset_align_self()- Align-self
set_margin()/get_margin()- Marginsset_padding()/get_padding()- Paddingset_border()/get_border()- Bordersset_margin_auto()- Auto margins
set_position_type()- Position (relative/absolute)set_position()- Position setting
set_display()- Display (flex/none)set_overflow()- Overflowset_direction()- Layout direction (LTR/RTL)set_node_type()- Node type (Default/Text)
print_node()- Print node tree structurereset()- Reset node statemark_dirty()/is_dirty()- Dirty marking management
- Memory Safety: Rust's ownership system ensures memory safety without manual memory deallocation
- Type Safety: Stronger type checking reduces runtime errors
- Concurrency Safety: Rust's concurrency model ensures thread safety
- Zero-cost Abstractions: Rust's zero-cost abstractions guarantee performance
- Naming Convention: Follows Rust naming conventions (snake_case)
- Memory Management: Uses
Rc<RefCell<>>for reference counting, automatic memory management - Error Handling: Uses Rust's
Resulttype for error handling - Optional Parameters: Uses
Option<T>instead of C++ optional parameters
- ✅ All C++ API features are implemented
- ✅ Layout algorithm is fully consistent with the C++ version
- ✅ All test cases pass
- ✅ Performance is comparable to the C++ version
Contributions are welcome! Please ensure:
- Code Formatting: Run
cargo fmtto ensure code formatting is correct - Code Checking: Run
cargo clippyto ensure there are no warnings - Tests Pass: Run
cargo testto ensure all tests pass - Documentation Updates: Update relevant documentation and comments
- Commit Messages: Use clear commit messages
- Fork the project
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Create a Pull Request
- Follow Rust official code style
- Use meaningful variable and function names
- Add necessary documentation comments
- Write unit tests
This project is licensed under the MIT License. See the LICENSE file for details.
- Taitank C++ - Original C++ implementation
- Yoga - Reference implementation of Flexbox layout algorithm
- ✅ Core functionality complete
- ✅ All tests passing
- ✅ API documentation complete
- ✅ Example code complete
- ✅ Performance benchmarks
- ✅ Multi-platform support
- Add more examples
- Performance optimizations
- Extended documentation
- Community feedback and improvements