项目作者: jswrenn

项目描述 :
Versatile Analog Literals for Rust
高级语言: RenderScript
项目地址: git://github.com/jswrenn/analit.git
创建时间: 2015-04-12T00:17:07Z
项目社区:https://github.com/jswrenn/analit

开源协议:MIT License

下载


Analit: Analog Literals for Rust

For all of Rust’s great improvements on the status quo of systems languages, one feature has been sorely missing. No, it’s not higher-kinded-types, or integer generics, or having a name that includes the letter ‘C’. It’s analog literals. Ever since Eelis debuted “Analog Literals” in 2005 as a C++ utility, the ability to draw geometry out using ASCII art has set a new bar for what constitutes a minimal-viable-language.

Examples

Analog literals follow a simple syntactic pattern. The pointy corners of things are marked by ‘+’ characters, one unit in the x-axis is represented by ‘—‘, and one unit in the Y and Z axes are represented by ‘|’ and ‘/‘, respectively. The reason two characters are used to represent just one unit in the x-axis is to compensate for the rectangular shape that characters are rendered with. Analog expressions return a tuple reflecting the dimensions of the drawing. But enough talk—let’s see some examples:

One-Dimensional

A line of length two along the X axis:

  1. assert_eq!(2, analit!(
  2. +----+
  3. ));

A line of length two along the Y axis:

  1. assert_eq!(2, analit!(
  2. +
  3. |
  4. |
  5. +
  6. ));

A line of length two along the Z axis:

  1. assert_eq!(2,analit!(
  2. +
  3. /
  4. /
  5. +
  6. ));

Two-Dimensional

Two dimensional literals have proven themselves especially valuable to GUI programmers.

A (2,1) rectangle defined across X and Y:

  1. assert_eq!((2,1),analit!(
  2. +----+
  3. | |
  4. +----+
  5. ));

…across X and Z:

  1. assert_eq!((2,1),analit!(
  2. +----+
  3. / /
  4. +----+
  5. ));

…across Y and Z:

  1. assert_eq!((2,1),analit!(
  2. +
  3. /|
  4. / +
  5. + /
  6. |/
  7. +
  8. ));

Three-Dimensional

It’s time to dig those red-and-blue glasses out from between the couch cushions; we’re going into the next dimension!

  1. assert_eq!((1,1,3),analit!(
  2. +--+
  3. / /|
  4. / / +
  5. / / /
  6. +--+ /
  7. | |/
  8. +--+
  9. ));

It’s like it’s coming right out of the screen!

Using Analog Literals in Your Next Project*

Simply add the following to your Cargo.toml

  1. [dependencies.analit]
  2. git = "https://github.com/jswrenn/analit"

Or, from the registry:

  1. [dependencies]
  2. analit = "*"

*Please don’t.