Class: Rust::CWrapperGenerator::WrapperFn
- Inherits:
-
Object
- Object
- Rust::CWrapperGenerator::WrapperFn
- Defined in:
- lib/rust_require/c_wrapper_generator.rb
Overview
Rust code of a wrapper function
Instance Method Summary collapse
-
#initialize(original_name, inputs, output) ⇒ WrapperFn
constructor
original_name: name of the fn to be wrapped (String) inputs: input types in order (Array) output: output type (String || nil).
-
#to_s ⇒ Object
returns string of rust code.
Constructor Details
#initialize(original_name, inputs, output) ⇒ WrapperFn
original_name: name of the fn to be wrapped (String) inputs: input types in order (Array) output: output type (String || nil)
46 47 48 49 50 |
# File 'lib/rust_require/c_wrapper_generator.rb', line 46 def initialize(original_name, inputs, output) @original_name = original_name @inputs = inputs @output = output end |
Instance Method Details
#to_s ⇒ Object
returns string of rust code
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rust_require/c_wrapper_generator.rb', line 53 def to_s # convert inputs input_types = @inputs.map { |t| Rust::Types.find_type(t) } c_inputs = input_types.map { |t| t.c_input_type } #C input types ([String]) input_str = c_inputs.map.with_index { |t,i| "c#{i}: #{t}" }.join(',') #fn foo_wrapper(input_str) ... input_conversions = input_types.map.with_index { |t,i| t.c_input_conversion("c#{i}") }.join(",") #code used to convert input types to c types # convert output output_type = Rust::Types.find_type(@output) c_output = output_type.c_output_type output_conversion = output_type.c_output_conversion('output') " #[no_mangle]\n pub extern \"C\" fn _\#{@original_name.gsub('::','_')}_wrapper(\#{input_str}) -> \#{c_output} {\n let output = \#{@original_name}(\#{input_conversions});\n \#{output_conversion}\n }\n END\nend\n" |