Class: Rust::Types::String

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_type, #ffi_input_type, #ffi_output_type, #initialize, rust_type, #rust_type_regex

Constructor Details

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

Instance Method Details

#c_input_conversion(slice) ⇒ Object



28
29
30
# File 'lib/rust_require/types/string.rb', line 28

def c_input_conversion(slice)
  not_implemented
end

#c_input_typeObject



10
11
12
# File 'lib/rust_require/types/string.rb', line 10

def c_input_type
  not_implemented
end

#c_output_conversion(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rust_require/types/string.rb', line 16

def c_output_conversion(name)
  "  {\n      let mut \#{name} = \#{name};\n      \#{name}.shrink_to_fit();\n      let tuple = (\#{name}.as_ptr(), \#{name}.len());\n      std::mem::forget(\#{name});\n      tuple\n  }\n  CODE\nend\n"

#c_output_typeObject



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

def c_output_type; '(*const u8,usize)'; end

#ffi_typeObject



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

def ffi_type; Rust::Slice.by_value; end

#not_implementedObject

Raises:

  • (NotImplementedError)


6
7
8
# File 'lib/rust_require/types/string.rb', line 6

def not_implemented
  raise NotImplementedError, 'String as rust input type is not supported, use &str instead!'
end

#ruby_input_conversion(str) ⇒ Object



39
40
41
# File 'lib/rust_require/types/string.rb', line 39

def ruby_input_conversion(str)
  not_implemented
end

#ruby_output_conversion(slice) ⇒ Object



34
35
36
37
# File 'lib/rust_require/types/string.rb', line 34

def ruby_output_conversion(slice)
  (start,len) = slice.unpack
  start.read_string(len.to_i).force_encoding("UTF-8")
end