Skip to content

Instantly share code, notes, and snippets.

@brendanzab
Forked from anonymous/RustSyntaxProposal
Last active December 15, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanzab/5231244 to your computer and use it in GitHub Desktop.
Save brendanzab/5231244 to your computer and use it in GitHub Desktop.

The first stage would be to unify the struct and type keywords.

Current syntax

struct Name {
    first: ~str,
    last: ~str
}
 
struct Point(int, int);

struct Celcius(float);
struct Kelvin(float);
 
type Coordinate = Point; // alias

New syntax

type Name {
    first: ~str,
    last: ~str
}
 
type Point(int, int);

type Celcius(float);
type Kelvin(float);
 
type Coordinate = Point; // alias

Changing the syntax/keyword for enum would be more challenging.

type Name {
first: ~str,
last: ~str
}
type Shape { Circle(int) | Rect(int, int) } // Variants with constructors
type Direction { North | South | East | West } // without constructors
enum Flags {
Optimise = 1,
Debug = 2,
Assemble = 4,
Default { Optimise | Debug } // Not sure about this??
}
type Point(int, int);
fn stream<T>() -> (Port<T>, Chan<T>);
type Coordinate = Point; // alias or typedef
type Celcius(float);
type Kelvin(float);
fn celcius_to_kelvin(cel: Celcius) -> Kelvin {
return Kelvin(*cel + 273.0); // Construct Kelvin type from float
}
fn main() {
let name = Name { first: ~"John", last: ~"Smith" };
let shape = @Circle(20);
let point = Point(10,20);
let flags = Flags::Optimise; // Use rustic namespace syntax
let temp = Celcius(0);
let temp = celcius_to_kelvin(temp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment