#ipc #swift #schema #cargo #derive #code-generation #serialization

app cargo-cargo-derive-ipc-schema-for-swift

Code-generator to IPC to Swift

1 unstable release

Uses old Rust 2015

0.1.0 May 15, 2018

#2500 in Database interfaces

MIT license

23KB
587 lines

Rust -> Swift IPC Data Schema Translator

Eonil

Generates Swift data-types and serialization code for IPC(inter-process communication) to Rust.

You define data schema in Rust code, and execute this tool to derive corresponding Swift-side data-types and serializations. You can perform Rust-side serializaton with serde. and Swift-side serialization code will be generated.

Intermediate messages will be coded in JSON.

How to Use

  1. Make a root level module named to_swift.
  2. Define message data types in there.
  3. Execute this tool on Cargo workspace root.

An example is included in source tree.

Type Mappings

Rust to/from Swift.

std::bool                   <->     Bool
std::i64                    <->     Int64
std::f64                    <->     Float64
std::String                 <->     String
std::option::Option         <->     Optional
std::vec::Vec               <->     Array
(enum)                      <->     (enum)
(struct)                    <->     (struct)

Any other types will not be supported and code-generator will fail with an error.

  • All fields must be pub.
  • Generated Swift-side serialization code supports only default serde behavior. Any customizations won't work. So DO NOT customize serde behavior to make it work on Swift side.
  • Only JSON container protocol is supported. Others maybe work if you can encode/decode them in Swift-side, but haven't been tested.

Goal

  • Reliability.
  • Simplicity.
  • Easeness.

Limitations

  • No support for Box type. So no recursive data type.
  • No support for HashMap (or any other associated collection) type.

Non-Goal

  • Performance. Make it work first.
  • Other container protocol else than JSON.
  • Generic enum or struct types.
  • Nested modules. All types will be placed in flat namespace in Swift.

Constributions and License

Initial version has been written by Eonil. This project is licensed under "MIT License". Any contributions will become same license with this project.

Dependencies

~3.5–4.5MB
~93K SLoC