rscsv 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7abdc4faa83ed5581cff993c3dcf4e19d8ed9c7f
4
+ data.tar.gz: d3e5dfe0f089ed0213ff940427e3054ecc36371d
5
+ SHA512:
6
+ metadata.gz: 8cfe748a3ba4395a6b5f078b39e34ba88adfa2d5b5b43b3156aad7b3f4cba9f8900ef5de7a79a3fe04897a31bc8cc4db90170f111ee602ae14a4ef7538a58396
7
+ data.tar.gz: 53b9a16030dfe87fd98dbd5ad91a8cef028d35528081571f52044ddefecbf3ca698d263ec4ed437a7b6285d16b3e4cd9958f19d2e96a909da3ff52582227b6df
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /target/
11
+ *.bundle
12
+ *.so
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,11 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ - 2.3.3
6
+ before_install:
7
+ - gem install bundler -v 1.14.6
8
+ - if [ ! -e "$HOME/.cargo/bin" ]; then curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y; fi
9
+ - export PATH="$HOME/.cargo/bin:$PATH"
10
+ - rustup default stable
11
+ - rustc --version
@@ -0,0 +1,80 @@
1
+ [root]
2
+ name = "rscsv"
3
+ version = "0.1.0"
4
+ dependencies = [
5
+ "csv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
6
+ "helix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
7
+ ]
8
+
9
+ [[package]]
10
+ name = "byteorder"
11
+ version = "1.0.0"
12
+ source = "registry+https://github.com/rust-lang/crates.io-index"
13
+
14
+ [[package]]
15
+ name = "cslice"
16
+ version = "0.3.0"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+
19
+ [[package]]
20
+ name = "cstr-macro"
21
+ version = "0.1.0"
22
+ source = "registry+https://github.com/rust-lang/crates.io-index"
23
+
24
+ [[package]]
25
+ name = "csv"
26
+ version = "0.15.0"
27
+ source = "registry+https://github.com/rust-lang/crates.io-index"
28
+ dependencies = [
29
+ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
30
+ "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
31
+ "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
32
+ ]
33
+
34
+ [[package]]
35
+ name = "helix"
36
+ version = "0.6.0"
37
+ source = "registry+https://github.com/rust-lang/crates.io-index"
38
+ dependencies = [
39
+ "cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
40
+ "cstr-macro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
41
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
42
+ "libcruby-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
43
+ ]
44
+
45
+ [[package]]
46
+ name = "libc"
47
+ version = "0.2.22"
48
+ source = "registry+https://github.com/rust-lang/crates.io-index"
49
+
50
+ [[package]]
51
+ name = "libcruby-sys"
52
+ version = "0.6.0"
53
+ source = "registry+https://github.com/rust-lang/crates.io-index"
54
+ dependencies = [
55
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
56
+ ]
57
+
58
+ [[package]]
59
+ name = "memchr"
60
+ version = "1.0.1"
61
+ source = "registry+https://github.com/rust-lang/crates.io-index"
62
+ dependencies = [
63
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
64
+ ]
65
+
66
+ [[package]]
67
+ name = "rustc-serialize"
68
+ version = "0.3.24"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+
71
+ [metadata]
72
+ "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
73
+ "checksum cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f8cb7306107e4b10e64994de6d3274bd08996a7c1322a27b86482392f96be0a"
74
+ "checksum cstr-macro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db53fddba18cdd35477a7213a3ef6acfbfa333c31b42ce019e544c4a1420a06f"
75
+ "checksum csv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ef22b37c7a51c564a365892c012dc0271221fdcc64c69b19ba4d6fa8bd96d9c"
76
+ "checksum helix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3d0b8579a68e79a629d9c2f4717dbf5e2b467a7d7afb38c737d573d46331ac"
77
+ "checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502"
78
+ "checksum libcruby-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bf276325da1f1b20cd68108b33c02dfcad26ff4f4d7fdac4cd2a5aac8f04ae5"
79
+ "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
80
+ "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
@@ -0,0 +1,12 @@
1
+ [package]
2
+ name = "rscsv"
3
+ version = "0.1.0"
4
+ authors = ["Ville Lautanala <lautis@gmail.com>"]
5
+
6
+ [lib]
7
+
8
+ crate-type = ["cdylib"]
9
+
10
+ [dependencies]
11
+ helix = "0.6.0"
12
+ csv = "0.15.0"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rscsv.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ville Lautanala
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # Rscsv
2
+
3
+ Fast CSV using Rust extensions. Currently writing CSV is implemented.
4
+
5
+ [![Build Status](https://travis-ci.org/lautis/rscsv.svg?branch=master)](https://travis-ci.org/lautis/rscsv)
6
+
7
+ ## Installation
8
+
9
+ This gem requires Rust (~> 1.17) and Cargo to be installed. With those
10
+ requirements fulfilled, rscsv can be installed like any other gem:
11
+
12
+ ```
13
+ gem install rscsv
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ require 'rscsv'
20
+
21
+ Rscsv::Writer.generate_lines([['1', '2', '3'], ['3', '4', '5']])
22
+ # => 1,2,3\n4,5,6\n
23
+ Rscsv::Writer.generate_line(['1', '2', '3'])
24
+ # => 1,2,3\n
25
+ ```
26
+
27
+ This is 3x faster than using native Ruby `CSV.generate`.
@@ -0,0 +1,27 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+ require 'helix_runtime/build_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ helix_tasks = HelixRuntime::BuildTask.new('rscsv')
9
+
10
+ # Monkey-patch project name as directory name varies during installation
11
+ module HelixRuntime
12
+ class Project
13
+ def name
14
+ 'rscsv'
15
+ end
16
+ end
17
+ end
18
+
19
+ namespace :helix do
20
+ desc 'Build rscsv'
21
+ task build: ['helix:pre_build', 'helix:check_path'] do
22
+ helix_tasks.project.build
23
+ end
24
+ end
25
+
26
+ task :spec => :build
27
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.dirname(__FILE__) + '/../lib'
4
+
5
+ require 'benchmark/ips'
6
+ require 'securerandom'
7
+ require 'rscsv'
8
+ require 'csv'
9
+
10
+ rows = (0...1000).map do
11
+ (0...10).map { SecureRandom.hex }
12
+ end
13
+
14
+ Benchmark.ips do |x|
15
+ x.report('Ruby CSV') do |times|
16
+ times.times do
17
+ CSV.generate do |csv|
18
+ rows.each { |row| csv << row }
19
+ end
20
+ end
21
+ end
22
+
23
+ x.report('rscsv') do |times|
24
+ times.times { Rscsv::Writer.generate_lines(rows) }
25
+ end
26
+
27
+ x.compare!
28
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rscsv"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ all:
2
+ rake helix:build
3
+ clean:
4
+ rm -rf ../target
5
+
6
+ install: ;
@@ -0,0 +1,5 @@
1
+ if !system('cargo --version') || !system('rustc --version')
2
+ raise 'You have to install Rust with Cargo (https://www.rust-lang.org/)'
3
+ end
4
+
5
+ require 'rake'
@@ -0,0 +1,7 @@
1
+ require 'helix_runtime'
2
+ require 'rscsv/native'
3
+ require 'rscsv/version'
4
+
5
+ module Rscsv
6
+ Writer = RscsvWriter
7
+ end
@@ -0,0 +1,3 @@
1
+ module Rscsv
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rscsv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rscsv'
8
+ spec.version = Rscsv::VERSION
9
+ spec.authors = ['Ville Lautanala']
10
+ spec.email = ['lautis@gmail.com']
11
+
12
+ spec.summary = 'Rust-powered CSV'
13
+ spec.description = 'Fast CSV using Rust extensions.' \
14
+ 'Currently only writes CSV.'
15
+ spec.homepage = 'https://github.com/lautis/rscsv'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+ spec.extensions = Dir['ext/extconf.rb']
25
+
26
+ spec.add_dependency 'helix_runtime', '~> 0.6.0'
27
+ spec.add_development_dependency 'bundler', '~> 1.14'
28
+ spec.add_development_dependency 'rake', '~> 12.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'benchmark-ips', '~> 2.7'
31
+ end
@@ -0,0 +1,86 @@
1
+ #[macro_use]
2
+ extern crate helix;
3
+ extern crate csv;
4
+
5
+ use helix::sys;
6
+ use helix::sys::VALUE;
7
+ use helix::{UncheckedValue, CheckResult, CheckedValue, ToRust};
8
+
9
+ struct VecWrap<T>(Vec<T>);
10
+
11
+ impl<T> UncheckedValue<VecWrap<T>> for VALUE
12
+ where VALUE: UncheckedValue<T>
13
+ {
14
+ fn to_checked(self) -> CheckResult<VecWrap<T>> {
15
+ if unsafe { sys::RB_TYPE_P(self, sys::T_ARRAY) } {
16
+ let len = unsafe { sys::RARRAY_LEN(self) };
17
+ let ptr = unsafe { sys::RARRAY_PTR(self) };
18
+ for i in 0..len {
19
+ let val = unsafe { *ptr.offset(i) };
20
+ if let Err(error) = val.to_checked() {
21
+ return Err(format!("Failed to convert value for Vec<T>: {}", error));
22
+ }
23
+ }
24
+ Ok(unsafe { CheckedValue::<VecWrap<T>>::new(self) })
25
+ } else {
26
+ let val = unsafe { CheckedValue::<String>::new(sys::rb_inspect(self)) };
27
+ Err(format!("No implicit conversion of {} into Vec<String>",
28
+ val.to_rust()))
29
+ }
30
+ }
31
+ }
32
+
33
+ impl ToRust<VecWrap<String>> for CheckedValue<VecWrap<String>>
34
+ where VALUE: UncheckedValue<String>,
35
+ CheckedValue<String>: ToRust<String>
36
+ {
37
+ fn to_rust(self) -> VecWrap<String> {
38
+ let len = unsafe { sys::RARRAY_LEN(self.inner) };
39
+ let ptr = unsafe { sys::RARRAY_PTR(self.inner) };
40
+ let mut vec: Vec<String> = Vec::with_capacity(len as usize);
41
+ for i in 0..len {
42
+ let val = unsafe { *ptr.offset(i) };
43
+ let checked = val.to_checked().unwrap();
44
+ vec.push(checked.to_rust());
45
+ }
46
+ return VecWrap(vec);
47
+ }
48
+ }
49
+
50
+ impl ToRust<VecWrap<VecWrap<String>>> for CheckedValue<VecWrap<VecWrap<String>>>
51
+ where VALUE: UncheckedValue<VecWrap<String>>,
52
+ CheckedValue<VecWrap<String>>: ToRust<VecWrap<String>>
53
+ {
54
+ fn to_rust(self) -> VecWrap<VecWrap<String>> {
55
+ let len = unsafe { sys::RARRAY_LEN(self.inner) };
56
+ let ptr = unsafe { sys::RARRAY_PTR(self.inner) };
57
+ let mut vec: Vec<VecWrap<String>> = Vec::with_capacity(len as usize);
58
+ for i in 0..len {
59
+ let val = unsafe { *ptr.offset(i) };
60
+ let checked = val.to_checked().unwrap();
61
+ vec.push(checked.to_rust());
62
+ }
63
+ return VecWrap(vec);
64
+ }
65
+ }
66
+
67
+ ruby! {
68
+ class RscsvWriter {
69
+ def generate_line(row: VecWrap<String>) -> String {
70
+ let mut writer = csv::Writer::from_memory();
71
+ writer.write(row.0.into_iter()).unwrap();
72
+ return writer.into_string();
73
+ }
74
+
75
+ def generate_lines(rows: VecWrap<VecWrap<String>>) -> String {
76
+ let mut writer = csv::Writer::from_memory();
77
+ let vec = rows.0;
78
+
79
+ for row in vec {
80
+ writer.write(row.0.into_iter()).unwrap();
81
+ }
82
+
83
+ return writer.into_string();
84
+ }
85
+ }
86
+ }
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rscsv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ville Lautanala
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: helix_runtime
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: benchmark-ips
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ description: Fast CSV using Rust extensions.Currently only writes CSV.
84
+ email:
85
+ - lautis@gmail.com
86
+ executables: []
87
+ extensions:
88
+ - ext/extconf.rb
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Cargo.lock
95
+ - Cargo.toml
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/benchmark
101
+ - bin/console
102
+ - bin/setup
103
+ - ext/Makefile
104
+ - ext/extconf.rb
105
+ - lib/rscsv.rb
106
+ - lib/rscsv/version.rb
107
+ - rscsv.gemspec
108
+ - src/lib.rs
109
+ homepage: https://github.com/lautis/rscsv
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.11
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Rust-powered CSV
133
+ test_files: []