Class: Rust::Types::StrSlice

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

Instance Attribute Summary

Attributes inherited from Type

#rust_type

Instance Method Summary collapse

Methods inherited from Type

#c_input_type, #c_type, #ffi_input_type, #ffi_output_type, #initialize, rust_type

Constructor Details

This class inherits a constructor from Rust::Types::Type

Instance Method Details

#c_input_conversion(slice) ⇒ Object



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

def c_input_conversion(slice)
  "#{slice}"
end

#c_output_conversion(name) ⇒ Object



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

def c_output_conversion(name)
  not_implemented
end

#c_output_typeObject



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

def c_output_type
  not_implemented
end

#ffi_typeObject



79
# File 'lib/rust_require/types/string.rb', line 79

def ffi_type; Rust::Slice.by_value; end

#not_implementedObject

Raises:

  • (NotImplementedError)


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

def not_implemented
  raise NotImplementedError, '&mut str/&str as rust output parameter is not supported, use String instead!'
end

#ruby_input_conversion(str) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/rust_require/types/string.rb', line 85

def ruby_input_conversion(str)
  str.encode!(Encoding::UTF_8)
  len = str.bytesize
  start = FFI::MemoryPointer.from_string(str)
  start.autorelease = false # no GC
  Rust::Slice.from(start.address, len)
end

#ruby_output_conversion(slice) ⇒ Object



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

def ruby_output_conversion(slice)
  not_implemented
end

#rust_type_regexObject



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

def rust_type_regex
  /^&(mut)?( )?str$/
end