halton 0.2.1.1 → 0.2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aae4af6af8ca0e3913593d6562fdc53c62595d072555803908f20f3058e0f3a
4
- data.tar.gz: bf500fc02cf93d2600d5b7196b89029dcf6866e61e96ff76eba179058e84b49f
3
+ metadata.gz: 2a65d2ef8aa05f9ff2b905cd199b67c457c22f6916be59df4fff97a92af0a48e
4
+ data.tar.gz: 15b62c7f8c05f1bcc9d206d3f228012fc1839a11095d6cc67cf046996696477c
5
5
  SHA512:
6
- metadata.gz: 9cacb8002e1418286806abb9fe6a9a3bdf01b4908ee6e90bf509706d659fdff3db1a3b8079f153ae968990312137ed9d5d94c1742c2ea031c0e8931df8ba73b0
7
- data.tar.gz: f8f7b0edf5be22cbf60e186ed7d7db9aca74531909f9372a902306bfd925df15c988e34b385bb37c6c2327cce4fd0f624954736b93c9b99fe4cf2c05671c8cee
6
+ metadata.gz: ca1ad0a5551d63dc6009b11afe17f8d792af1181564794c4a707bd9fdb08311459d73c3ff13dc76a7e067ac72fa510089a4bf8d09a093bf5f761af0d45284f8a
7
+ data.tar.gz: 11ebf433af39d7047da8c1cf99404bc09eb422ebc0f4e0c532ef0fdda96a7dbf37f89b09e01ca76c258dd03566f74653af7a096ece95d39117820b247bf36e21
@@ -0,0 +1,446 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "0.7.18"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "ansi_term"
16
+ version = "0.12.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
19
+ dependencies = [
20
+ "winapi",
21
+ ]
22
+
23
+ [[package]]
24
+ name = "atty"
25
+ version = "0.2.14"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
28
+ dependencies = [
29
+ "hermit-abi",
30
+ "libc",
31
+ "winapi",
32
+ ]
33
+
34
+ [[package]]
35
+ name = "bindgen"
36
+ version = "0.59.2"
37
+ source = "registry+https://github.com/rust-lang/crates.io-index"
38
+ checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8"
39
+ dependencies = [
40
+ "bitflags",
41
+ "cexpr",
42
+ "clang-sys",
43
+ "clap",
44
+ "env_logger",
45
+ "lazy_static",
46
+ "lazycell",
47
+ "log",
48
+ "peeking_take_while",
49
+ "proc-macro2",
50
+ "quote",
51
+ "regex",
52
+ "rustc-hash",
53
+ "shlex",
54
+ "which",
55
+ ]
56
+
57
+ [[package]]
58
+ name = "bitflags"
59
+ version = "1.3.2"
60
+ source = "registry+https://github.com/rust-lang/crates.io-index"
61
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
62
+
63
+ [[package]]
64
+ name = "cexpr"
65
+ version = "0.6.0"
66
+ source = "registry+https://github.com/rust-lang/crates.io-index"
67
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
68
+ dependencies = [
69
+ "nom",
70
+ ]
71
+
72
+ [[package]]
73
+ name = "cfg-if"
74
+ version = "1.0.0"
75
+ source = "registry+https://github.com/rust-lang/crates.io-index"
76
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
77
+
78
+ [[package]]
79
+ name = "clang-sys"
80
+ version = "1.3.1"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+ checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21"
83
+ dependencies = [
84
+ "glob",
85
+ "libc",
86
+ "libloading",
87
+ ]
88
+
89
+ [[package]]
90
+ name = "clap"
91
+ version = "2.34.0"
92
+ source = "registry+https://github.com/rust-lang/crates.io-index"
93
+ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
94
+ dependencies = [
95
+ "ansi_term",
96
+ "atty",
97
+ "bitflags",
98
+ "strsim 0.8.0",
99
+ "textwrap",
100
+ "unicode-width",
101
+ "vec_map",
102
+ ]
103
+
104
+ [[package]]
105
+ name = "darling"
106
+ version = "0.13.1"
107
+ source = "registry+https://github.com/rust-lang/crates.io-index"
108
+ checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4"
109
+ dependencies = [
110
+ "darling_core",
111
+ "darling_macro",
112
+ ]
113
+
114
+ [[package]]
115
+ name = "darling_core"
116
+ version = "0.13.1"
117
+ source = "registry+https://github.com/rust-lang/crates.io-index"
118
+ checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324"
119
+ dependencies = [
120
+ "fnv",
121
+ "ident_case",
122
+ "proc-macro2",
123
+ "quote",
124
+ "strsim 0.10.0",
125
+ "syn",
126
+ ]
127
+
128
+ [[package]]
129
+ name = "darling_macro"
130
+ version = "0.13.1"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b"
133
+ dependencies = [
134
+ "darling_core",
135
+ "quote",
136
+ "syn",
137
+ ]
138
+
139
+ [[package]]
140
+ name = "either"
141
+ version = "1.6.1"
142
+ source = "registry+https://github.com/rust-lang/crates.io-index"
143
+ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
144
+
145
+ [[package]]
146
+ name = "env_logger"
147
+ version = "0.9.0"
148
+ source = "registry+https://github.com/rust-lang/crates.io-index"
149
+ checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
150
+ dependencies = [
151
+ "atty",
152
+ "humantime",
153
+ "log",
154
+ "regex",
155
+ "termcolor",
156
+ ]
157
+
158
+ [[package]]
159
+ name = "fnv"
160
+ version = "1.0.7"
161
+ source = "registry+https://github.com/rust-lang/crates.io-index"
162
+ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
163
+
164
+ [[package]]
165
+ name = "glob"
166
+ version = "0.3.0"
167
+ source = "registry+https://github.com/rust-lang/crates.io-index"
168
+ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
169
+
170
+ [[package]]
171
+ name = "halton"
172
+ version = "0.1.0"
173
+ dependencies = [
174
+ "halton 0.2.1",
175
+ "lazy_static",
176
+ "magnus",
177
+ ]
178
+
179
+ [[package]]
180
+ name = "halton"
181
+ version = "0.2.1"
182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
183
+ checksum = "be629448e3d85a1be12868f190df524655fea8ec3f143e14d803e298f618acae"
184
+
185
+ [[package]]
186
+ name = "hermit-abi"
187
+ version = "0.1.19"
188
+ source = "registry+https://github.com/rust-lang/crates.io-index"
189
+ checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
190
+ dependencies = [
191
+ "libc",
192
+ ]
193
+
194
+ [[package]]
195
+ name = "humantime"
196
+ version = "2.1.0"
197
+ source = "registry+https://github.com/rust-lang/crates.io-index"
198
+ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
199
+
200
+ [[package]]
201
+ name = "ident_case"
202
+ version = "1.0.1"
203
+ source = "registry+https://github.com/rust-lang/crates.io-index"
204
+ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
205
+
206
+ [[package]]
207
+ name = "lazy_static"
208
+ version = "1.4.0"
209
+ source = "registry+https://github.com/rust-lang/crates.io-index"
210
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
211
+
212
+ [[package]]
213
+ name = "lazycell"
214
+ version = "1.3.0"
215
+ source = "registry+https://github.com/rust-lang/crates.io-index"
216
+ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
217
+
218
+ [[package]]
219
+ name = "libc"
220
+ version = "0.2.119"
221
+ source = "registry+https://github.com/rust-lang/crates.io-index"
222
+ checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
223
+
224
+ [[package]]
225
+ name = "libloading"
226
+ version = "0.7.3"
227
+ source = "registry+https://github.com/rust-lang/crates.io-index"
228
+ checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
229
+ dependencies = [
230
+ "cfg-if",
231
+ "winapi",
232
+ ]
233
+
234
+ [[package]]
235
+ name = "log"
236
+ version = "0.4.14"
237
+ source = "registry+https://github.com/rust-lang/crates.io-index"
238
+ checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
239
+ dependencies = [
240
+ "cfg-if",
241
+ ]
242
+
243
+ [[package]]
244
+ name = "magnus"
245
+ version = "0.1.0"
246
+ source = "registry+https://github.com/rust-lang/crates.io-index"
247
+ checksum = "1825dcc83398c263845f82fdf847f2599a6d51a4da6e668e5ca8e84309eea8df"
248
+ dependencies = [
249
+ "bindgen",
250
+ "magnus-macros",
251
+ ]
252
+
253
+ [[package]]
254
+ name = "magnus-macros"
255
+ version = "0.1.0"
256
+ source = "registry+https://github.com/rust-lang/crates.io-index"
257
+ checksum = "27968fcabe2ef7e35b8331d71a62882282996f6222c133c0255cf7f33b8d9b48"
258
+ dependencies = [
259
+ "darling",
260
+ "proc-macro2",
261
+ "quote",
262
+ "syn",
263
+ ]
264
+
265
+ [[package]]
266
+ name = "memchr"
267
+ version = "2.4.1"
268
+ source = "registry+https://github.com/rust-lang/crates.io-index"
269
+ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
270
+
271
+ [[package]]
272
+ name = "minimal-lexical"
273
+ version = "0.2.1"
274
+ source = "registry+https://github.com/rust-lang/crates.io-index"
275
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
276
+
277
+ [[package]]
278
+ name = "nom"
279
+ version = "7.1.0"
280
+ source = "registry+https://github.com/rust-lang/crates.io-index"
281
+ checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109"
282
+ dependencies = [
283
+ "memchr",
284
+ "minimal-lexical",
285
+ "version_check",
286
+ ]
287
+
288
+ [[package]]
289
+ name = "peeking_take_while"
290
+ version = "0.1.2"
291
+ source = "registry+https://github.com/rust-lang/crates.io-index"
292
+ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
293
+
294
+ [[package]]
295
+ name = "proc-macro2"
296
+ version = "1.0.36"
297
+ source = "registry+https://github.com/rust-lang/crates.io-index"
298
+ checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
299
+ dependencies = [
300
+ "unicode-xid",
301
+ ]
302
+
303
+ [[package]]
304
+ name = "quote"
305
+ version = "1.0.15"
306
+ source = "registry+https://github.com/rust-lang/crates.io-index"
307
+ checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
308
+ dependencies = [
309
+ "proc-macro2",
310
+ ]
311
+
312
+ [[package]]
313
+ name = "regex"
314
+ version = "1.5.4"
315
+ source = "registry+https://github.com/rust-lang/crates.io-index"
316
+ checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
317
+ dependencies = [
318
+ "aho-corasick",
319
+ "memchr",
320
+ "regex-syntax",
321
+ ]
322
+
323
+ [[package]]
324
+ name = "regex-syntax"
325
+ version = "0.6.25"
326
+ source = "registry+https://github.com/rust-lang/crates.io-index"
327
+ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
328
+
329
+ [[package]]
330
+ name = "rustc-hash"
331
+ version = "1.1.0"
332
+ source = "registry+https://github.com/rust-lang/crates.io-index"
333
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
334
+
335
+ [[package]]
336
+ name = "shlex"
337
+ version = "1.1.0"
338
+ source = "registry+https://github.com/rust-lang/crates.io-index"
339
+ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
340
+
341
+ [[package]]
342
+ name = "strsim"
343
+ version = "0.8.0"
344
+ source = "registry+https://github.com/rust-lang/crates.io-index"
345
+ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
346
+
347
+ [[package]]
348
+ name = "strsim"
349
+ version = "0.10.0"
350
+ source = "registry+https://github.com/rust-lang/crates.io-index"
351
+ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
352
+
353
+ [[package]]
354
+ name = "syn"
355
+ version = "1.0.86"
356
+ source = "registry+https://github.com/rust-lang/crates.io-index"
357
+ checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
358
+ dependencies = [
359
+ "proc-macro2",
360
+ "quote",
361
+ "unicode-xid",
362
+ ]
363
+
364
+ [[package]]
365
+ name = "termcolor"
366
+ version = "1.1.2"
367
+ source = "registry+https://github.com/rust-lang/crates.io-index"
368
+ checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
369
+ dependencies = [
370
+ "winapi-util",
371
+ ]
372
+
373
+ [[package]]
374
+ name = "textwrap"
375
+ version = "0.11.0"
376
+ source = "registry+https://github.com/rust-lang/crates.io-index"
377
+ checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
378
+ dependencies = [
379
+ "unicode-width",
380
+ ]
381
+
382
+ [[package]]
383
+ name = "unicode-width"
384
+ version = "0.1.9"
385
+ source = "registry+https://github.com/rust-lang/crates.io-index"
386
+ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
387
+
388
+ [[package]]
389
+ name = "unicode-xid"
390
+ version = "0.2.2"
391
+ source = "registry+https://github.com/rust-lang/crates.io-index"
392
+ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
393
+
394
+ [[package]]
395
+ name = "vec_map"
396
+ version = "0.8.2"
397
+ source = "registry+https://github.com/rust-lang/crates.io-index"
398
+ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
399
+
400
+ [[package]]
401
+ name = "version_check"
402
+ version = "0.9.4"
403
+ source = "registry+https://github.com/rust-lang/crates.io-index"
404
+ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
405
+
406
+ [[package]]
407
+ name = "which"
408
+ version = "4.2.4"
409
+ source = "registry+https://github.com/rust-lang/crates.io-index"
410
+ checksum = "2a5a7e487e921cf220206864a94a89b6c6905bfc19f1057fa26a4cb360e5c1d2"
411
+ dependencies = [
412
+ "either",
413
+ "lazy_static",
414
+ "libc",
415
+ ]
416
+
417
+ [[package]]
418
+ name = "winapi"
419
+ version = "0.3.9"
420
+ source = "registry+https://github.com/rust-lang/crates.io-index"
421
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
422
+ dependencies = [
423
+ "winapi-i686-pc-windows-gnu",
424
+ "winapi-x86_64-pc-windows-gnu",
425
+ ]
426
+
427
+ [[package]]
428
+ name = "winapi-i686-pc-windows-gnu"
429
+ version = "0.4.0"
430
+ source = "registry+https://github.com/rust-lang/crates.io-index"
431
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
432
+
433
+ [[package]]
434
+ name = "winapi-util"
435
+ version = "0.1.5"
436
+ source = "registry+https://github.com/rust-lang/crates.io-index"
437
+ checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
438
+ dependencies = [
439
+ "winapi",
440
+ ]
441
+
442
+ [[package]]
443
+ name = "winapi-x86_64-pc-windows-gnu"
444
+ version = "0.4.0"
445
+ source = "registry+https://github.com/rust-lang/crates.io-index"
446
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
@@ -10,4 +10,4 @@ crate-type = ["cdylib"]
10
10
  [dependencies]
11
11
  halton = "0.2.1"
12
12
  lazy_static = "1"
13
- rutie = "0.8"
13
+ magnus = "0.1.0"
data/ext/halton/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "shellwords"
4
+
3
5
  class RakeCargoHelper
4
6
  attr_reader :gemname
5
7
 
6
- def initialize(gemname)
8
+ def initialize(gemname=File.basename(__dir__))
7
9
  @gemname = gemname
8
10
  end
9
11
 
@@ -36,6 +38,24 @@ class RakeCargoHelper
36
38
  @cargo_target_dir = dir || "target"
37
39
  end
38
40
 
41
+ def self.dld_flags
42
+ map = {"-L" => "-L native=", "-l" => "-l", "-F" => "-l framework="}
43
+ map.default_proc = proc {|_, key| "-C link_arg=#{key}"}
44
+ Shellwords.split(RbConfig::CONFIG["DLDFLAGS"]).flat_map do |arg|
45
+ k, v = arg.split(/(?<=..)/, 2)
46
+ case k
47
+ when "-L"
48
+ [k, "native=#{v}"]
49
+ when "-l"
50
+ [k, v]
51
+ when "-F"
52
+ ["-l", "framework=#{v}"]
53
+ else
54
+ ["-C", "link_arg=#{k}#{v}"]
55
+ end
56
+ end
57
+ end
58
+
39
59
  def install_dir
40
60
  File.expand_path(File.join("..", "..", "lib", gemname), __dir__)
41
61
  end
@@ -67,17 +87,18 @@ end
67
87
 
68
88
  desc "build gem native extension and copy to lib"
69
89
  task install: [:cd, :build] do
70
- helper = RakeCargoHelper.new("halton")
90
+ helper = RakeCargoHelper.new
71
91
  profile_dir = @dev ? "debug" : "release"
72
92
  source = File.join(RakeCargoHelper.cargo_target_dir, profile_dir, helper.rust_name)
73
93
  dest = File.join(helper.install_dir, helper.ruby_name)
74
94
  mkdir_p(helper.install_dir)
95
+ rm(dest) if File.exist?(dest)
75
96
  cp(source, dest)
76
97
  end
77
98
 
78
99
  desc "build gem native extension"
79
100
  task build: [:cargo, :cd] do
80
- sh "cargo", "build", *("--release" unless @dev)
101
+ sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *RakeCargoHelper.dld_flags
81
102
  end
82
103
 
83
104
  desc "clean up release build artifacts"
@@ -1,88 +1,39 @@
1
- use lazy_static::lazy_static;
2
- use rutie::{
3
- class, methods, module, wrappable_struct, AnyObject, Class, Float, Integer, Module, NilClass,
4
- Object, VM,
5
- };
1
+ use std::cell::RefCell;
6
2
 
7
- macro_rules! unwrap_raise {
8
- ($val:expr) => {
9
- #[allow(clippy::redundant_closure)]
10
- $val.map_err(|e| VM::raise_ex(e))
11
- .expect("exception should have been raised")
12
- };
13
- }
14
-
15
- macro_rules! raise {
16
- ($class:ty, $($arg:tt)*) => {{
17
- VM::raise(Class::from_existing(stringify!($class)), &format!($($arg)*));
18
- unreachable!()
19
- }};
20
- }
21
-
22
- fn any_object_or_nil<T>(obj: Option<T>) -> AnyObject
23
- where
24
- T: Into<AnyObject>,
25
- {
26
- obj.map(Into::into)
27
- .unwrap_or_else(|| NilClass::new().into())
28
- }
3
+ use magnus::{define_module, function, method, prelude::*, Error};
29
4
 
30
- module!(Halton);
5
+ #[magnus::wrap(class = "Halton::Sequence", free_immediatly, size)]
6
+ struct Sequence(RefCell<halton::Sequence>);
31
7
 
32
- methods!(
33
- Halton,
34
- rtself,
35
- fn halton_number(base: Integer, index: Integer) -> Float {
36
- Float::new(halton::number(
37
- unwrap_raise!(base).to_u64() as u8,
38
- unwrap_raise!(index).to_u64() as usize,
39
- ))
8
+ impl Sequence {
9
+ fn new(base: u8) -> Self {
10
+ Self(RefCell::new(halton::Sequence::new(base)))
40
11
  }
41
- );
42
12
 
43
- wrappable_struct!(halton::Sequence, SequenceWrapper, SEQUENCE_WRAPPER);
13
+ fn next(&self) -> Result<f64, Error> {
14
+ match self.0.try_borrow_mut().unwrap().next() {
15
+ Some(f) => Ok(f),
16
+ None => Err(Error::stop_iteration("iteration reached an end")),
17
+ }
18
+ }
44
19
 
45
- class!(Sequence);
20
+ fn skip(&self, n: usize) {
21
+ self.0.try_borrow_mut().unwrap().nth(n);
22
+ }
46
23
 
47
- methods!(
48
- Sequence,
49
- rtself,
50
- fn halton_sequence_new(base: Integer) -> AnyObject {
51
- let seq = halton::Sequence::new(unwrap_raise!(base).to_u64() as u8);
52
- Module::from_existing("Halton")
53
- .get_nested_class("Sequence")
54
- .wrap_data(seq, &*SEQUENCE_WRAPPER)
55
- },
56
- fn halton_sequence_next() -> Float {
57
- let seq = rtself.get_data_mut(&*SEQUENCE_WRAPPER);
58
- match seq.next() {
59
- Some(f) => Float::new(f),
60
- None => raise!(StopIteration, "iteration reached an end"),
61
- }
62
- },
63
- fn halton_sequence_skip(n: Integer) -> NilClass {
64
- let seq = rtself.get_data_mut(&*SEQUENCE_WRAPPER);
65
- seq.nth(unwrap_raise!(n).to_u64() as usize);
66
- NilClass::new()
67
- },
68
- fn halton_sequence_remaining() -> AnyObject {
69
- let seq = rtself.get_data(&*SEQUENCE_WRAPPER);
70
- any_object_or_nil(seq.size_hint().1.map(|i| Integer::new(i as i64)))
24
+ fn remaining(&self) -> Option<usize> {
25
+ self.0.try_borrow().unwrap().size_hint().1
71
26
  }
72
- );
27
+ }
73
28
 
74
- #[allow(non_snake_case)]
75
- #[no_mangle]
76
- pub extern "C" fn Init_halton() {
77
- Module::new("Halton").define(|module| {
78
- module.def_self("number", halton_number);
79
- module
80
- .define_nested_class("Sequence", None)
81
- .define(|class| {
82
- class.def_self("new", halton_sequence_new);
83
- class.def("next", halton_sequence_next);
84
- class.def("skip", halton_sequence_skip);
85
- class.def("remaining", halton_sequence_remaining);
86
- });
87
- });
29
+ #[magnus::init]
30
+ fn init() -> Result<(), Error> {
31
+ let module = define_module("Halton")?;
32
+ module.define_singleton_method("number", function!(halton::number, 2));
33
+ let class = module.define_class("Sequence", Default::default())?;
34
+ class.define_singleton_method("new", function!(Sequence::new, 1));
35
+ class.define_method("next", method!(Sequence::next, 0));
36
+ class.define_method("skip", method!(Sequence::skip, 1));
37
+ class.define_method("remaining", method!(Sequence::remaining, 0));
38
+ Ok(())
88
39
  }
data/lib/halton.rb CHANGED
@@ -129,7 +129,6 @@ module Halton
129
129
  #
130
130
  # Can be used to efficiently skip large sections of the sequence. For small
131
131
  # values of +n+ simply advances the sequence +n+ times.
132
- #
133
132
 
134
133
  ##
135
134
  # :method: remaining
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.1
4
+ version: 0.2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Sadler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-06 00:00:00.000000000 Z
11
+ date: 2022-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -36,6 +36,7 @@ extra_rdoc_files:
36
36
  - README.rdoc
37
37
  files:
38
38
  - README.rdoc
39
+ - ext/halton/Cargo.lock
39
40
  - ext/halton/Cargo.toml
40
41
  - ext/halton/Rakefile
41
42
  - ext/halton/src/lib.rs
@@ -66,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
67
  version: '0'
67
68
  requirements:
68
69
  - Rust >= 1.51.0
69
- rubygems_version: 3.2.3
70
+ rubygems_version: 3.4.0.dev
70
71
  signing_key:
71
72
  specification_version: 4
72
73
  summary: A module for generating Halton sequences