Class: Rust::Types::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/rust_require/types.rb

Overview

The base class for Types with simple defaults

Direct Known Subclasses

Bool, F32, F64, Nil, PrimitiveInteger, StrSlice, String

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeType

set @rust_type from class variable @rust_type



45
46
47
# File 'lib/rust_require/types.rb', line 45

def initialize
  @rust_type = self.class.rust_type
end

Instance Attribute Details

#rust_typeObject

name of the rust type (String) raises error when @rust_type is nil

Raises:

  • (NotImplementedError)


51
52
53
54
# File 'lib/rust_require/types.rb', line 51

def rust_type
  raise NotImplementedError, "This is a bug." if @rust_type.nil?
  @rust_type
end

Class Method Details

.rust_typeObject

accessor for @rust_type of Type class



42
# File 'lib/rust_require/types.rb', line 42

def self.rust_type; @rust_type; end

Instance Method Details

#c_input_conversion(name) ⇒ Object

rust code performing necessary conversions on input from ruby with name before passing it to original rust fn (String)



72
# File 'lib/rust_require/types.rb', line 72

def c_input_conversion(name); name; end

#c_input_typeObject

name of the type passed in from ruby (String)



65
# File 'lib/rust_require/types.rb', line 65

def c_input_type; c_type; end

#c_output_conversion(name) ⇒ Object

rust code performing necessary conversions on output with name from rust fn before returning it to ruby (String)



76
# File 'lib/rust_require/types.rb', line 76

def c_output_conversion(name); name; end

#c_output_typeObject

name of the type returned by the wrapper fn to ruby



68
# File 'lib/rust_require/types.rb', line 68

def c_output_type; c_type; end

#c_typeObject



62
# File 'lib/rust_require/types.rb', line 62

def c_type; rust_type; end

#ffi_input_typeObject

returns symbol understood by ruby ffi gem corresponding to @rust_type as input



85
# File 'lib/rust_require/types.rb', line 85

def ffi_input_type; ffi_type; end

#ffi_output_typeObject

returns symbol understood by ruby ffi gem corresponding to @rust_type as output



88
# File 'lib/rust_require/types.rb', line 88

def ffi_output_type; ffi_type; end

#ffi_typeObject

shortcut for ffi type (input and output)



82
# File 'lib/rust_require/types.rb', line 82

def ffi_type; rust_type.to_sym; end

#ruby_input_conversion(obj) ⇒ Object

return value will directly be passed into the ffi fn



91
# File 'lib/rust_require/types.rb', line 91

def ruby_input_conversion(obj); obj; end

#ruby_output_conversion(obj) ⇒ Object

obj is return value of ffi fn return value will be the final result of ffi call



95
# File 'lib/rust_require/types.rb', line 95

def ruby_output_conversion(obj); obj; end

#rust_type_regexObject



58
59
60
# File 'lib/rust_require/types.rb', line 58

def rust_type_regex
  Regexp.new @rust_type
end