This document outlines the step-by-step plan for converting TA-Lib's C functions to Rust, starting with the MULT function as a prototype.
-
Fix
printRustLookbackFunctionSignature:- Generate proper Rust signature with parameters
- Add proper return type (
-> i32) - Remove braces from function generation
-
Fix
printRustDoublePrecisionFunctionSignature:- Generate proper Rust parameter types (
&[f64]for arrays) - Use proper borrowing for output parameters (
&mut i32) - Add proper return type (
-> RetCode) - Remove braces from function generation
- Generate proper Rust parameter types (
-
Fix
printRustSinglePrecisionFunctionSignature:- Generate proper Rust parameter types for single precision (
&[f32]) - Use consistent patterns for output parameters
- Add proper return type
- Remove braces from function generation
- Generate proper Rust parameter types for single precision (
- Added missing
TA_IN_PRICE_MASKconstant definition in gen_rust.c - Current output still has C code mixed with Rust code (
#elsestatements in the output) - Need to better understand how the preprocessor and template system work together
- Identify where the mixed C/Rust code is coming from
- Modify preprocessor logic to properly separate Rust and C code
- Ensure Rust-specific syntax is correctly used:
- For loops should use
for i in start..=endsyntax - Array access should use proper usize casting
- Output assignments should use Rust dereferencing
- Return statements should use Rust syntax
- For loops should use
-
Update templates in
src/ta_abstract/templates/:- Add proper Rust-specific structures to
ta_func_mod.rs.template - Update
ta_x.rs.templateto correctly handle Rust code - Add support for Rust-specific syntax in the templates
- Add proper Rust-specific structures to
-
Modify gen_code.c and gen_rust.c:
- Update
genRustCodePhase2to handle code conversion properly - Improve handling of C to Rust syntax differences
- Add proper filtering of C-specific code for Rust output
- Update
-
Create a basic
Cargo.tomlfile:- Define project name, version, and authors
- Add any necessary dependencies
- Define library structure
-
Create Rust module structure:
- Ensure
corestruct is properly defined - Set up proper module exports
- Implement RetCode and other supporting types
- Ensure
-
Test with MULT function:
- Generate code with
bin/gen_code - Verify the generated Rust code compiles
- Create simple test cases
- Compare results with C implementation
- Generate code with
-
Apply improvements based on testing:
- Refine template and code generation
- Fix any issues discovered
- Document lessons learned
- Extend implementation to handle SMA:
- Update optional parameter handling for SMA's time period
- Test SMA generation with
bin/gen_code - Verify SMA implementation matches C version
-
Document the Rust interface:
- Update README and documentation
- Provide usage examples
- Document any Rust-specific considerations
-
Final integration testing:
- Verify all functions work as expected
- Check performance against C implementation