rust_require 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 966cbdc98075f675ca524af3e52f323223e90ec9
4
- data.tar.gz: 3d005785bf2d5b58aa1597731b55d87ae7005577
3
+ metadata.gz: 484d36177135a18fa7f5e96964922ac838f76507
4
+ data.tar.gz: 1706cc6f34a642a562fa9c28ec4e00e0ace6bf40
5
5
  SHA512:
6
- metadata.gz: 8520b3eebee695a4e60ed080e973c2b29541a2e7eaaf4e9c35c3367f606bcc2392199a359778cbe968c2d7015096f62fad76fc15a692e0dd6d23d05be1d35651
7
- data.tar.gz: 4a95e25804bc3af66b47fba19076b645fcb30a7bdd681757fecf9fc102dd6e73ed9e57942ccc633047fbff2e24cb1affd1cdd18909eeaaf83351cc17dddf1872
6
+ metadata.gz: 78d8ab5c8913fb2707c4ef7cb925add94ee2effc133cbecb15bc25ebd07bfcb0ffd83eeafe955197a13953b8f0420abe06b3fe15301d2b81720297b75c564298
7
+ data.tar.gz: f791650c44a1aee9076e37d9a581bb73238563bbca48b4786ec2031945a51c8a7416a5b72d77f536d8dea5fbd8da662430b2824a570eef4e4ef8545f121c9fa4
data/lib/rust_require.rb CHANGED
@@ -12,6 +12,8 @@ require_relative 'rust_require/rustc.rb'
12
12
  require_relative 'rust_require/types.rb'
13
13
  require_relative 'rust_require/c_wrapper_generator.rb'
14
14
  require_relative 'rust_require/ruby_wrapper_generator.rb'
15
+ require_relative 'rust_require/struct.rb'
16
+
15
17
 
16
18
  # Types
17
19
  require_relative 'rust_require/types/primitives.rb'
@@ -78,7 +78,7 @@ module Rust
78
78
  [name.to_sym, type.ffi_output_type]
79
79
  end.flatten
80
80
 
81
- struct = Class.new(FFI::Struct)
81
+ struct = Class.new(Rust::Struct)
82
82
  struct.layout *fields
83
83
 
84
84
  mod.const_set(s['name'], struct)
@@ -0,0 +1,28 @@
1
+ module Rust
2
+ class Struct < FFI::Struct
3
+ alias_method :old_get, :"[]"
4
+ alias_method :old_set, :"[]="
5
+
6
+ # TODO maybe type & bounds checking?
7
+
8
+ def [](field)
9
+ if field.respond_to? :to_sym
10
+ field = field.to_sym
11
+ elsif field.respond_to? :to_s
12
+ field = field.to_s.to_sym
13
+ end
14
+
15
+ old_get(field)
16
+ end
17
+
18
+ def []=(field, obj)
19
+ if field.respond_to? :to_sym
20
+ field = field.to_sym
21
+ elsif field.respond_to? :to_s
22
+ field = field.to_s.to_sym
23
+ end
24
+
25
+ old_set(field, obj)
26
+ end
27
+ end
28
+ end
@@ -1 +1 @@
1
- VERSION = "0.2.3"
1
+ VERSION = "0.2.4"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rust_require
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Lackner
@@ -80,6 +80,7 @@ files:
80
80
  - lib/rust_require/ruby_wrapper_generator.rb
81
81
  - lib/rust_require/rust_require.rb
82
82
  - lib/rust_require/rustc.rb
83
+ - lib/rust_require/struct.rb
83
84
  - lib/rust_require/types.rb
84
85
  - lib/rust_require/types/primitives.rb
85
86
  - lib/rust_require/types/string.rb