1 unstable release

0.1.0 Sep 13, 2023

#1266 in Development tools

MIT/Apache

23KB
504 lines

type-protocol

A crate provding a simple syntax representing types inspired by the go programming language.


lib.rs:

A crate provding a simple syntax inspired by the go programming language for conveying the idea of types.

Universal Types

These are common datatype found in most languages.

  • Boolean Types: bool
  • Signed Integer Types: int or isize, int8, int16, int32, int64, int128
  • Unsigned Integer Types: uint or usize, uint8, uint16, uint32, uint64, uint128
  • Floating Point Types: float16, float32, float64
  • Char and String types: char, string

Extension Types

These are common special datatypes, prefixed with +.

  • +bytes
  • +dateTime, +date, +time, +duration
  • +decimal
  • +uuid
  • +rgb, +rgba

Types and Paths

Any string segment not starting with an reserved symbol is a Type or a Path if it is not a Builtin Type. Buildin types use snake_case so you should use PascalCase to avoid collision.

  • Named Types

MyType, Foöbár, Hello World, 2022

A validator can be provided to validate idents based on the user's needs.

The RustIdent validator will fail Hello World and 2022, while the AsciiIdent validator will fail Foöbár additionally.

Note type-protocol grammer treat whitespaces like normal characters, the user is responsible for stripping them if needed.

  • Paths

path::to::Type

  • Absolute Paths

::path::to::Type

Optional Types

?T represents a optional type like Option<T> or a nullable pointer.

e.g. ?string

Array Types

[N]T represents a fix sized array type like [[T;N]]. N has to be an integer.

e.g. [4]int

Vec Types

[]T represents a dynamic sized array type like Vec<T>.

e.g. []int

Set Types

[T] represents a collection of unique keys like HashSet<T>.

e.g. [string]

Map Types

[TKey]TValue represents a collection of keys and values like HashMap<T>.

e.g. [string]int

Hint Types

  • Foreign Hint

@T hints that T is a foreign type.

Dependencies

~0.3–1MB
~24K SLoC