Debian Codegraph @

third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/Helpers.rb

raw
1 def self.uniffi_in_range(i, type_name, min, max)
2 raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
3 i = i.to_int
4 raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
5 i
6 end
7
8 def self.uniffi_utf8(v)
9 raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
10 v = v.to_str.encode(Encoding::UTF_8)
11 raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
12 v
13 end
14
15 def self.uniffi_bytes(v)
16 raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
17 v.to_str
18 end