rusty_symbol 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Cargo.lock +16 -0
- data/Cargo.toml +11 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +15 -0
- data/benchmark.rb +29 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/examples/Gemfile +8 -0
- data/examples/Gemfile.lock +31 -0
- data/examples/example.rb +13 -0
- data/ext/Rakefile +3 -0
- data/ext/build.rb +24 -0
- data/ext/rusty_symbol/extconf.rb +3 -0
- data/lib/rusty_symbol.rb +5 -0
- data/lib/rusty_symbol/version.rb +3 -0
- data/rusty_symbol.gemspec +33 -0
- data/src/lib.rs +77 -0
- data/src/types.rs +12 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad5a3e24028724406439218973d97476d39e6a711a96dde74392ccce3740f844
|
4
|
+
data.tar.gz: 0ca877199717bf5f92572f834ba434b6496961306ebe1f56b38a767511e2cffd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9845c7414347a7481f6460e214a5ef858c3fcd99ab734c85e4aef756ad2a29c1803f38bbe5587c14c33a13994e2d471370d0d200f54165c7bb20342eec975bf
|
7
|
+
data.tar.gz: 3b6effab095198121f4707ec334eaf4df8fd5e03140a816a7ff3c085e081a6a2fa915592171a3b68400e9021937b0490a269adf7f92e1bb83f04b13533ae83ed
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
/**/*/vendor/bundle
|
10
|
+
/**/*/.bundle
|
11
|
+
|
12
|
+
# rspec failure tracking
|
13
|
+
.rspec_status
|
14
|
+
|
15
|
+
|
16
|
+
#Added by cargo
|
17
|
+
#
|
18
|
+
#already existing elements are commented out
|
19
|
+
|
20
|
+
/target
|
21
|
+
**/*.rs.bk
|
22
|
+
*.dylib
|
23
|
+
*.so
|
24
|
+
*.bundle
|
25
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tomisuker16@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Cargo.lock
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
2
|
+
# It is not intended for manual editing.
|
3
|
+
[[package]]
|
4
|
+
name = "libc"
|
5
|
+
version = "0.2.65"
|
6
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
7
|
+
|
8
|
+
[[package]]
|
9
|
+
name = "rusty_symbol"
|
10
|
+
version = "0.1.0"
|
11
|
+
dependencies = [
|
12
|
+
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
13
|
+
]
|
14
|
+
|
15
|
+
[metadata]
|
16
|
+
"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8"
|
data/Cargo.toml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rusty_symbol (0.1.3)
|
5
|
+
thermite
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
benchmark-ips (2.7.2)
|
11
|
+
coderay (1.1.2)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
method_source (0.9.2)
|
14
|
+
minitar (0.9)
|
15
|
+
pry (0.12.2)
|
16
|
+
coderay (~> 1.1.0)
|
17
|
+
method_source (~> 0.9.0)
|
18
|
+
rake (10.5.0)
|
19
|
+
rake-compiler (1.0.8)
|
20
|
+
rake
|
21
|
+
rspec (3.9.0)
|
22
|
+
rspec-core (~> 3.9.0)
|
23
|
+
rspec-expectations (~> 3.9.0)
|
24
|
+
rspec-mocks (~> 3.9.0)
|
25
|
+
rspec-core (3.9.0)
|
26
|
+
rspec-support (~> 3.9.0)
|
27
|
+
rspec-expectations (3.9.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.9.0)
|
30
|
+
rspec-mocks (3.9.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-support (3.9.0)
|
34
|
+
thermite (0.13.0)
|
35
|
+
minitar (~> 0.5)
|
36
|
+
rake (>= 10)
|
37
|
+
tomlrb (~> 1.2)
|
38
|
+
tomlrb (1.2.9)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
benchmark-ips
|
45
|
+
bundler (~> 2.0)
|
46
|
+
pry
|
47
|
+
rake (~> 10.0)
|
48
|
+
rake-compiler
|
49
|
+
rspec (~> 3.0)
|
50
|
+
rusty_symbol!
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 atomiyama
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# RustySymbol
|
2
|
+
|
3
|
+
`Symbol#start_with?` and `Symbol#end_with?` implemented in Rust.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rusty_symbol'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rusty_symbol
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
example code [here](./examples/example.rb).
|
23
|
+
```
|
24
|
+
:some_symbol.start_with?(:some) #=> true
|
25
|
+
:some_symbol.end_with?(:symbol) #=> true
|
26
|
+
:some_symbol.end_with?(:some) #=> false
|
27
|
+
:some_symbol.start_with?(:symbol) #=> false
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
You need install rustc compiler. [Installation](https://www.rust-lang.org/tools/install)
|
33
|
+
```bash
|
34
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
35
|
+
```
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rusty_symbol. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
48
|
+
|
49
|
+
## Code of Conduct
|
50
|
+
|
51
|
+
Everyone interacting in the RustyThread project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rusty_symbol/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require_relative "ext/build"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
require "rake/extensiontask"
|
8
|
+
|
9
|
+
task build: "thermite:build"
|
10
|
+
|
11
|
+
Rake::ExtensionTask.new("rusty_symbol") do |ext|
|
12
|
+
ext.lib_dir = "lib/rusty_symbol"
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => [:clobber, "thermite:build", :spec]
|
data/benchmark.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rusty_symbol"
|
2
|
+
require "benchmark/ips"
|
3
|
+
|
4
|
+
class Symbol
|
5
|
+
def _start_with?(*argv)
|
6
|
+
self.to_s.start_with?(*argv.map(&:to_s))
|
7
|
+
end
|
8
|
+
|
9
|
+
def _end_with?(*argv)
|
10
|
+
self.to_s.end_with?(*argv.map(&:to_s))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Benchmark.ips do |x|
|
15
|
+
x.report "Ruby" do
|
16
|
+
1_000_000.times do
|
17
|
+
:some_symbol._start_with?(:foo, :baz, :bar, :some)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
x.report "Rust" do
|
22
|
+
1_000_000.times do
|
23
|
+
:some_symbol.start_with?(:foo, :baz, :bar, :symbol)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
x.compare!
|
28
|
+
end
|
29
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rusty_symbol"
|
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
|
+
require "pry"
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
data/examples/Gemfile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/akifumitomiyama/work/private/rusty_symbol
|
3
|
+
specs:
|
4
|
+
rusty_symbol (0.1.0)
|
5
|
+
thermite (~> 0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
method_source (0.9.2)
|
12
|
+
minitar (0.9)
|
13
|
+
pry (0.12.2)
|
14
|
+
coderay (~> 1.1.0)
|
15
|
+
method_source (~> 0.9.0)
|
16
|
+
rake (13.0.1)
|
17
|
+
thermite (0.13.0)
|
18
|
+
minitar (~> 0.5)
|
19
|
+
rake (>= 10)
|
20
|
+
tomlrb (~> 1.2)
|
21
|
+
tomlrb (1.2.8)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
pry
|
28
|
+
rusty_symbol!
|
29
|
+
|
30
|
+
BUNDLED WITH
|
31
|
+
1.17.2
|
data/examples/example.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# with a argument typed Symbol
|
2
|
+
:symbol.start_with?(:sym) #=> true
|
3
|
+
:symbol.start_with?(:bol) #=> false
|
4
|
+
|
5
|
+
:symbol.end_with?(:bol) #=> true
|
6
|
+
:symbol.end_with?(:sym) #=> false
|
7
|
+
|
8
|
+
# with multiple arguments typed Symbol
|
9
|
+
:symbol.start_with?(:foo, :sym) #=> true
|
10
|
+
:symbol.start_with?(:foo, :bol) #=> false
|
11
|
+
|
12
|
+
:symbol.end_with?(:foo, :bol) #=> true
|
13
|
+
:symbol.end_with?(:foo, :sym) #=> false
|
data/ext/Rakefile
ADDED
data/ext/build.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'thermite/tasks'
|
2
|
+
|
3
|
+
Thermite::Config.prepend(
|
4
|
+
Module.new do
|
5
|
+
def shared_library
|
6
|
+
@shared_library ||= "#{library_name}.#{RbConfig::CONFIG["DLEXT"] || 'so'}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def ruby_extension_dir
|
10
|
+
@ruby_extension_dir ||= @options.fetch(:ruby_extension_dir, 'lib')
|
11
|
+
end
|
12
|
+
|
13
|
+
def ruby_extension_path
|
14
|
+
ruby_path(ruby_extension_dir, shared_library)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
)
|
18
|
+
|
19
|
+
project_dir = File.expand_path('..', __dir__)
|
20
|
+
Thermite::Tasks.new(
|
21
|
+
cargo_project_path: project_dir,
|
22
|
+
ruby_project_path: project_dir,
|
23
|
+
ruby_extension_dir: "lib/rusty_symbol"
|
24
|
+
)
|
data/lib/rusty_symbol.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rusty_symbol/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rusty_symbol"
|
8
|
+
spec.version = RustySymbol::VERSION
|
9
|
+
spec.authors = ["atomiyama"]
|
10
|
+
spec.email = ["tomisuker16@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Symbol#start_with? and #end_with? methods implemented in Rust"
|
13
|
+
spec.description = "Symbol#start_with? and #end_with? methods implemented in Rust"
|
14
|
+
spec.homepage = "https://github.com/atomiyama/rusty_symbol"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
spec.extensions = ['ext/Rakefile']
|
24
|
+
|
25
|
+
spec.add_dependency "thermite"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rake-compiler"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "pry"
|
32
|
+
spec.add_development_dependency "benchmark-ips"
|
33
|
+
end
|
data/src/lib.rs
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
extern crate libc;
|
2
|
+
|
3
|
+
use libc::{ c_int, c_void, c_char, uintptr_t, c_ulong };
|
4
|
+
use std::ffi::{ CString, CStr };
|
5
|
+
use std::slice;
|
6
|
+
use types::Boolean;
|
7
|
+
|
8
|
+
type VALUE = c_ulong;
|
9
|
+
type ID = uintptr_t;
|
10
|
+
#[allow(non_camel_case_types)]
|
11
|
+
type void = c_void;
|
12
|
+
#[allow(non_camel_case_types)]
|
13
|
+
type c_func = *const void;
|
14
|
+
|
15
|
+
mod types;
|
16
|
+
|
17
|
+
extern "C" {
|
18
|
+
static rb_cSymbol: VALUE;
|
19
|
+
|
20
|
+
fn rb_define_method(klass: VALUE, name: *const c_char, func: c_func, argc: c_int);
|
21
|
+
|
22
|
+
fn rb_id2name(id: ID) -> *const c_char;
|
23
|
+
|
24
|
+
fn rb_sym2id(id: VALUE) -> ID;
|
25
|
+
}
|
26
|
+
|
27
|
+
extern fn rb_sym_start_with(argc: c_int, argv: *const VALUE, rb_self: VALUE) -> VALUE {
|
28
|
+
// if no arguments return false
|
29
|
+
if argc == 0 { return Boolean::False as VALUE };
|
30
|
+
|
31
|
+
// parse variable arguments into vec.
|
32
|
+
let argv = unsafe { slice::from_raw_parts(argv, argc as usize).to_vec() };
|
33
|
+
|
34
|
+
// transform Symbol into String
|
35
|
+
let receiver_ptr: *const c_char = unsafe { rb_id2name(rb_sym2id(rb_self)) };
|
36
|
+
let receiver_str: String = unsafe { CStr::from_ptr(receiver_ptr).to_string_lossy().into_owned() };
|
37
|
+
|
38
|
+
for arg in argv {
|
39
|
+
let sym_ptr: *const c_char = unsafe { rb_id2name(rb_sym2id(arg)) };
|
40
|
+
let string: String = unsafe { CStr::from_ptr(sym_ptr).to_string_lossy().into_owned() };
|
41
|
+
|
42
|
+
if receiver_str.starts_with(&string) { return Boolean::True as VALUE }
|
43
|
+
};
|
44
|
+
Boolean::False as VALUE
|
45
|
+
}
|
46
|
+
|
47
|
+
extern fn rb_sym_end_with(argc: c_int, argv: *const VALUE, rb_self: VALUE) -> VALUE {
|
48
|
+
// if no arguments return false
|
49
|
+
if argc == 0 { return Boolean::False as VALUE };
|
50
|
+
|
51
|
+
// parse variable arguments into vec.
|
52
|
+
let argv = unsafe { slice::from_raw_parts(argv, argc as usize).to_vec() };
|
53
|
+
|
54
|
+
// transform Symbol into String
|
55
|
+
let receiver_ptr: *const c_char = unsafe { rb_id2name(rb_sym2id(rb_self)) };
|
56
|
+
let receiver_str: String = unsafe { CStr::from_ptr(receiver_ptr).to_string_lossy().into_owned() };
|
57
|
+
|
58
|
+
for arg in argv {
|
59
|
+
let sym_ptr: *const c_char = unsafe { rb_id2name(rb_sym2id(arg)) };
|
60
|
+
let string: String = unsafe { CStr::from_ptr(sym_ptr).to_string_lossy().into_owned() };
|
61
|
+
|
62
|
+
if receiver_str.ends_with(&string) { return Boolean::True as VALUE }
|
63
|
+
};
|
64
|
+
Boolean::False as VALUE
|
65
|
+
}
|
66
|
+
|
67
|
+
#[allow(non_snake_case)]
|
68
|
+
#[no_mangle]
|
69
|
+
pub extern "C" fn Init_rusty_symbol() {
|
70
|
+
let sym_start_with = CString::new("start_with?").unwrap();
|
71
|
+
let sym_end_with = CString::new("end_with?").unwrap();
|
72
|
+
|
73
|
+
unsafe {
|
74
|
+
rb_define_method(rb_cSymbol, sym_start_with.as_ptr(), rb_sym_start_with as c_func, -1);
|
75
|
+
rb_define_method(rb_cSymbol, sym_end_with.as_ptr(), rb_sym_end_with as c_func, -1);
|
76
|
+
}
|
77
|
+
}
|
data/src/types.rs
ADDED
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rusty_symbol
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- atomiyama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thermite
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake-compiler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: benchmark-ips
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: 'Symbol#start_with? and #end_with? methods implemented in Rust'
|
112
|
+
email:
|
113
|
+
- tomisuker16@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions:
|
116
|
+
- ext/Rakefile
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Cargo.lock
|
124
|
+
- Cargo.toml
|
125
|
+
- Gemfile
|
126
|
+
- Gemfile.lock
|
127
|
+
- LICENSE.txt
|
128
|
+
- README.md
|
129
|
+
- Rakefile
|
130
|
+
- benchmark.rb
|
131
|
+
- bin/console
|
132
|
+
- bin/setup
|
133
|
+
- examples/Gemfile
|
134
|
+
- examples/Gemfile.lock
|
135
|
+
- examples/example.rb
|
136
|
+
- ext/Rakefile
|
137
|
+
- ext/build.rb
|
138
|
+
- ext/rusty_symbol/extconf.rb
|
139
|
+
- lib/rusty_symbol.rb
|
140
|
+
- lib/rusty_symbol/version.rb
|
141
|
+
- rusty_symbol.gemspec
|
142
|
+
- src/lib.rs
|
143
|
+
- src/types.rs
|
144
|
+
homepage: https://github.com/atomiyama/rusty_symbol
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubygems_version: 3.0.6
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: 'Symbol#start_with? and #end_with? methods implemented in Rust'
|
167
|
+
test_files: []
|