Module: TreeHaver::Backends::Rust
- Defined in:
- lib/tree_haver/backends/rust.rb
Overview
Rust backend using the tree_stump gem
This backend wraps the tree_stump gem, which provides Ruby bindings to tree-sitter written in Rust. It offers native performance with Rust’s safety guarantees and includes precompiled binaries for common platforms.
tree_stump supports incremental parsing and the Query API, making it suitable for editor/IDE use cases where performance is critical.
Platform Compatibility
-
MRI Ruby: ✓ Full support
-
JRuby: ✗ Cannot load native extensions (runs on JVM)
-
TruffleRuby: ✗ magnus/rb-sys incompatible with TruffleRuby’s C API emulation
Defined Under Namespace
Class Method Summary collapse
- .available? ⇒ Boolean
-
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend.
-
.reset! ⇒ void
private
Reset the load state (primarily for testing).
Class Method Details
.available? ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tree_haver/backends/rust.rb', line 35 def available? return @loaded if @load_attempted # rubocop:disable ThreadSafety/ClassInstanceVariable @load_attempted = true # rubocop:disable ThreadSafety/ClassInstanceVariable # tree_stump uses magnus which requires MRI's C API # It doesn't work on JRuby or TruffleRuby unless RUBY_ENGINE == "ruby" @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable return @loaded end begin require "tree_stump" @loaded = true # rubocop:disable ThreadSafety/ClassInstanceVariable rescue LoadError @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end @loaded # rubocop:disable ThreadSafety/ClassInstanceVariable end |
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend
71 72 73 74 75 76 77 78 79 |
# File 'lib/tree_haver/backends/rust.rb', line 71 def capabilities return {} unless available? { backend: :rust, query: true, bytes_field: true, incremental: false, # TreeStump doesn't currently expose incremental parsing to Ruby } end |
.reset! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Reset the load state (primarily for testing)
60 61 62 63 |
# File 'lib/tree_haver/backends/rust.rb', line 60 def reset! @load_attempted = false # rubocop:disable ThreadSafety/ClassInstanceVariable @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end |