Rust to Ruby
Recorder: the polyglot Rust adapter (rustc + a generated driver). Public functions are recordable.
Axum and Actix routes are found by analyze.
Constructs
Result<T, E>:Err(e)is a raise. Map the error enum's variants to Ruby error classes (class ParseError < StandardError) orArgumentErrorfor invalid input.panic!/unwraponNone-> raise only where a recorded case shows it.Option<T>->nil;unwrap_or(d)->|| d(or explicit nil check when false is a value);map/and_then->&.then.- Structs + impl ->
Data.defineor classes; traits -> modules (duck typing); enums with data ->Data.defineper variant +case ... in. - Iterators:
iter().filter().map().collect::<Vec<_>>()->select.map;fold->reduce;zip,enumerate->zip,each_with_index;chunks(n)->each_slice(n). - Axum/Actix:
Json(x)with(StatusCode::CREATED, Json(x))->render json: x, status: :created; extractors (Path,Query,Json) ->params. - serde:
#[serde(rename_all = "camelCase")],skip_serializing_ifdecide the JSON keys.
Traps
- Integer types wrap in release builds (
wrapping_*explicitly), panic in debug: the recording shows which. Ruby never overflows./truncates toward zero (Ruby floors);%takes the dividend's sign (remainder);rem_euclid->%for positive divisors. - Rounding:
f64::roundrounds half away from zero like Ruby;round_ties_even->round(half: :even).format!("{:.2}", x)rounds half to even on the binary value. - Strings:
len()counts bytes (bytesize);chars().count()counts code points (length). Slicing by byte offsets panics on a char boundary. - HashMap iteration order is random: sort where the output came from one;
BTreeMapis sorted. - Float formatting:
1.0_f64.to_string() == "1"; Ruby1.0.to_s == "1.0".