Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.
Rust agent-skillsclaude-codeclicode-migrationcodexffigolangjavajavascriptmcpmigrationnapiperformanceportingpyo3pythonrewriterubyrusttypescript
# frozen_string_literal: true
# The Rust port of `lib/textkit/`, generated by rust-anything: the same module functions, each
# calling the Rust extension `textkit_rs_native`. Load it in place of the original files.
# Regenerate with `rust-anything refresh`.
require_relative "textkit_rs_native"
module Textkit
module Nums
def self.page_count(total, per_page = 10)
RustAnythingNativeTextkitRs.page_count(total, per_page)
end
def self.mean(values)
RustAnythingNativeTextkitRs.mean(values)
end
def self.clamp(value, low, high)
RustAnythingNativeTextkitRs.clamp(value, low, high)
end
end
end
module Textkit
module Words
def self.slugify(text, sep = "-", max: nil)
RustAnythingNativeTextkitRs.slugify(text, sep, max)
end
def self.word_count(text)
RustAnythingNativeTextkitRs.word_count(text)
end
def self.titleize(text)
RustAnythingNativeTextkitRs.titleize(text)
end
end
end
module Textkit
module Words
# `slugify` over many `text` values kept in Rust: built once, then each `run` maps them all
# in one call, on all cores.
class SlugifyBatch
def initialize(texts)
@native = RustAnythingNativeTextkitRs::SlugifyBatch.new(texts.to_a)
end
# The result for every item, in order.
def run(sep = "-", max: nil)
@native.run(sep, max)
end
end
end
end
module Textkit
module Nums
# `page_count` over many `total` values kept in Rust: built once, then each `run` maps them all
# in one call, on all cores.
class PageCountBatch
def initialize(totals)
@native = RustAnythingNativeTextkitRs::PageCountBatch.new(totals.to_a)
end
# The result for every item, in order.
def run(per_page = 10)
@native.run(per_page)
end
# Indexes of the items whose result is at least `min`, highest result first.
def rank(per_page = 10, min: 0)
@native.rank(per_page, min)
end
end
end
end
module Textkit
module Words
# `word_count` over many `text` values kept in Rust: built once, then each `run` maps them all
# in one call, on all cores.
class WordCountBatch
def initialize(texts)
@native = RustAnythingNativeTextkitRs::WordCountBatch.new(texts.to_a)
end
# The result for every item, in order.
def run()
@native.run()
end
end
end
end