RustQ.Meta.Desugar (rustq v1.0.0-rc.19)

Copy Markdown View Source

Rewrites standard-library calls that are other Rusty-Elixir into that Rusty-Elixir, before RustQ.Meta.Ownership and lowering see a body, so lowering keeps to forms Rust has:

  • Map.new/1,2, MapSet.new/1,2, and Enum.into/2,3 into an empty collection are a comprehension collecting into it;
  • Enum.group_by/2,3 is a map filled by a loop, and Enum.uniq/1 and Enum.uniq_by/2 keep the items a set has not seen;
  • a generator over Enum.with_index(list) enumerates the list in place.

Where a rewrite needs what only lowering knows, it leaves an internal form for lowering to resolve: __rustq_items__(list) iterates a list as its ownership allows, and __rustq_owned__(item, list) is an item of list, copied where that costs nothing and cloned otherwise.

Summary

Functions

A one-argument function applied to value, inlined: fn name -> name.len() end applied to item is item.len(), and &key/1 applied to it is key(item).

Rewrites body's standard-library calls that are other Rusty-Elixir.

Functions

apply_function(other, value)

@spec apply_function(Macro.t(), Macro.t()) :: Macro.t()

A one-argument function applied to value, inlined: fn name -> name.len() end applied to item is item.len(), and &key/1 applied to it is key(item).

desugar(body)

@spec desugar(Macro.t()) :: Macro.t()

Rewrites body's standard-library calls that are other Rusty-Elixir.