All Projects → Hywan → code-tour-rs

Hywan / code-tour-rs

Licence: BSD-3-Clause License
Enhanced example-based learning, i.e. awesome example user experience

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to code-tour-rs

example-orbitdb-todomvc
TodoMVC with OrbitDB
Stars: ✭ 17 (-15%)
Mutual labels:  example
db2-samples
Db2 application code, configuration samples, and other examples
Stars: ✭ 56 (+180%)
Mutual labels:  example
Hello-GLUT
A very simple "Hello World!" GLUT application demonstrating how to write OpenGL applications in C with MinGW and MSVC.
Stars: ✭ 27 (+35%)
Mutual labels:  example
widgets playground
Showcase example for https://github.com/therecipe/qt
Stars: ✭ 50 (+150%)
Mutual labels:  example
rest-api-endpoints
🌾 WordPress REST API endpoints
Stars: ✭ 31 (+55%)
Mutual labels:  example
iOS ARkit2 Multiusers
An example implemented multiplayer experience in ARKit2
Stars: ✭ 19 (-5%)
Mutual labels:  example
todo-graphql-example
Example Todo app on top of json-graphql-server
Stars: ✭ 20 (+0%)
Mutual labels:  example
react-native-css-modules-with-media-queries-example
An example app to show how CSS Media Queries work in React Native.
Stars: ✭ 18 (-10%)
Mutual labels:  example
scenic asteroids
A toy Asteroids clone written in Elixir with the Scenic UI library
Stars: ✭ 42 (+110%)
Mutual labels:  example
play-java-ebean-example
Example Play application showing Java with Ebean
Stars: ✭ 54 (+170%)
Mutual labels:  example
riot realworld example app
Exemplary real world application built with Riot.js v6 🖐👍
Stars: ✭ 16 (-20%)
Mutual labels:  example
SeatLayout
A seat selection library for Android with an example for selecting seats for flights, sports venue, theatres, etc
Stars: ✭ 30 (+50%)
Mutual labels:  example
hugo-bare-min-theme
A bare minimum theme for Hugo (https://gohugo.io) to help develop and debug Hugo sites -- https://hugo-bare-min.netlify.com/,
Stars: ✭ 71 (+255%)
Mutual labels:  example
ksonnet-cheat-sheet
No description or website provided.
Stars: ✭ 18 (-10%)
Mutual labels:  example
api-examples
Plesk API-RPC usage examples
Stars: ✭ 79 (+295%)
Mutual labels:  example
play-scala-chatroom-example
Play chatroom with Scala API
Stars: ✭ 43 (+115%)
Mutual labels:  example
learning-python
notes and codes while learning python
Stars: ✭ 71 (+255%)
Mutual labels:  example
aita dataset
AITA dataset based on r/AmItheAsshole/
Stars: ✭ 27 (+35%)
Mutual labels:  example
reinforcement learning financial trading
MATLAB example on how to use Reinforcement Learning for developing a financial trading model
Stars: ✭ 94 (+370%)
Mutual labels:  example
haxe
Qt binding for Haxe | Showcase example for https://github.com/therecipe/qt
Stars: ✭ 21 (+5%)
Mutual labels:  example

Logo, just triangles
Code Tour

Introduction

This project is an attempt to improve Rust example-based learning approach.

Imagine the following example file:

#[derive(Debug)]
struct S {
    x: i32,
    y: i32,
}

fn main() {
    // Declare something.
    // Because it's an example.
    let a = S { x: 7, y: 42 };

    let b = a.x + a.y;

    // Here is the result!
    let c = b + 1;
}

When one runs the example with cargo run --example foo, nothing is printed! It means the author of the example must add println! or dbg! instructions everytime. Moreover the users are going to miss the comments, that's really unfortunate.

Enter code_tour.

Let's rewrite the example as such:

use code_tour::code_tour;

#[derive(Debug)]
struct S {
    x: i32,
    y: i32,
}

#[code_tour]
fn main() {
    /// Declare something.
    /// Because it's an example.
    let a = S { x: 7, y: 42 };

    let b = a.x + a.y;

    /// Here is the result!
    let c = b + 1;
}

Let's re-execute the example as previously, and we'll see:

$ cargo run --example foo

cargo run example

The example annotations are replicated on the output during the execution.

An annotation must be a comment of kind /// or /** … */ that introduces a let binding. That's all for the moment!

Interactive mode

Running the example with --features interactive will display a “Press Enter to continue, otherwise Ctrl-C to exit.” message after each step of your code.

$ cargo run --example foo --features interactive

cargo run example interactive

Quiet mode

Running the example with the environment variable CODE_TOUR_QUIET set will turn code-tour silent. Note that it won't disable the interactive mode (which is on purpose).

$ CODE_TOUR_QUIET=1 cargo run --example foo

Better source code display

Running the example with cargo +nightly will generate a better output for the code, by using Span::source_text.

$ cargo +nightly run --example foo

Install

This is a classic Rust project, thus add code-tour to your Cargo.toml file, and that's it.

License

BSD-3-Clause, see LICENSE.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].