Skip to content

"Rusty" API is NOT Idiomatic Rust #25

Open
@4LT

Description

@4LT

First, let me say that I am by no means a Rust expert. However, I have noticed several cases while reviewing the Unit WASM "Rusty" API where the code is not very conventional (lit. doesn't follow conventions) of typical Rust code.

Right off the bat, I see the use of the uwr namespace in the name of functions, like uwr_init_ctx. That makes the fully qualified name unit_wasm::rusty::uwr_init_ctx. This is an instance of smurf naming. Generally this would be avoided by importing the module instead of the function, as follows:

use wasm_unit::rusty;

// in the body of a function...
  rusty::init_ctx(...);

Otherwise* there are cases where ergonomic constructs could be used (avoiding raw pointers, not requiring writing code that is unsafe, use of higher-level types, etc.). I know that the WASM host-plugin interface is inherently low-level (basically limited to C-language constructs) but I believe the convention for FFI-centered APIs is to split into a low-level crate (usually suffixed -sys) interaction with C interfaces and a high-level crate that provides ergonomic and safe abstractions. As I see it, the current wasm_unit "ffi" module performs the lowest-level interactions, but the "rusty" module is still very low-level itself. "rusty" even suffers as a medium-level abstraction because it still requires writing unsafe code to use (e.g. manipulating raw pointers).

Thus I believe that the "rusty" API ought not be named "rusty" because the name suggests a more idiomatic interface, or the API should be redesigned to be more high-level and idiomatic, or at least medium-level providing safe abstractions to ease the development of a high-level API.

*there are more cases of naming breaking convention, but I feel it would be pedantic to list them here in full.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions