{"id":16872248,"url":"https://github.com/hywan/code-tour-rs","last_synced_at":"2025-03-22T07:31:12.124Z","repository":{"id":57607813,"uuid":"281157595","full_name":"Hywan/code-tour-rs","owner":"Hywan","description":"Enhanced example-based learning, i.e. awesome example user experience","archived":false,"fork":false,"pushed_at":"2020-10-11T09:27:32.000Z","size":122,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T09:21:27.418Z","etag":null,"topics":["documentation","example","rust","rust-lang","user-experience"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hywan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-20T15:39:30.000Z","updated_at":"2024-04-02T15:00:08.000Z","dependencies_parsed_at":"2022-08-30T04:42:19.864Z","dependency_job_id":null,"html_url":"https://github.com/Hywan/code-tour-rs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hywan%2Fcode-tour-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hywan%2Fcode-tour-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hywan%2Fcode-tour-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hywan%2Fcode-tour-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hywan","download_url":"https://codeload.github.com/Hywan/code-tour-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244925081,"owners_count":20532873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["documentation","example","rust","rust-lang","user-experience"],"created_at":"2024-10-13T15:14:03.019Z","updated_at":"2025-03-22T07:31:10.658Z","avatar_url":"https://github.com/Hywan.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"./doc/logo.png\" alt=\"Logo, just triangles\" /\u003e\u003cbr /\u003e\n  Code Tour\n\u003c/h1\u003e\n\n## Introduction\n\nThis project is an attempt to improve Rust example-based learning\napproach.\n\nImagine the following example file:\n\n```rust\n#[derive(Debug)]\nstruct S {\n    x: i32,\n    y: i32,\n}\n\nfn main() {\n    // Declare something.\n    // Because it's an example.\n    let a = S { x: 7, y: 42 };\n\n    let b = a.x + a.y;\n\n    // Here is the result!\n    let c = b + 1;\n}\n```\n\nWhen one runs the example with `cargo run --example foo`, nothing is\nprinted!  It means the author of the example must add `println!` or\n`dbg!` instructions everytime. Moreover the users are going to miss\nthe comments, that's really unfortunate.\n\n**Enter `code_tour`**.\n\nLet's rewrite the example as such:\n\n```rust\nuse code_tour::code_tour;\n\n#[derive(Debug)]\nstruct S {\n    x: i32,\n    y: i32,\n}\n\n#[code_tour]\nfn main() {\n    /// Declare something.\n    /// Because it's an example.\n    let a = S { x: 7, y: 42 };\n\n    let b = a.x + a.y;\n\n    /// Here is the result!\n    let c = b + 1;\n}\n```\n\nLet's re-execute the example as previously, and we'll see:\n\n```rust\n$ cargo run --example foo\n```\n\n![cargo run example](./doc/cargo_run_example.png)\n\nThe example annotations are replicated on the output during the\nexecution.\n\nAn annotation must be a comment of kind `///` or `/** … */` that\nintroduces a `let` binding. That's all for the moment!\n\n### Interactive mode\n\nRunning the example with `--features interactive` will display a\n“Press Enter to continue, otherwise Ctrl-C to exit.” message after\neach step of your code.\n\n```rust\n$ cargo run --example foo --features interactive\n```\n\n![cargo run example interactive](./doc/cargo_run_example_interactive.png)\n\n### Quiet mode\n\nRunning the example with the environment variable `CODE_TOUR_QUIET`\nset will turn code-tour silent. Note that it won't disable the\ninteractive mode (which is on purpose).\n\n```rust\n$ CODE_TOUR_QUIET=1 cargo run --example foo\n```\n\n### Better source code display\n\nRunning the example with `cargo +nightly` will generate a better\noutput for the code, by using\n[`Span::source_text`](https://doc.rust-lang.org/proc_macro/struct.Span.html#method.source_text).\n\n```rust\n$ cargo +nightly run --example foo\n```\n\n## Install\n\nThis is a classic Rust project, thus add `code-tour` to your\n`Cargo.toml` file, and that's it.\n\n## License\n\n`BSD-3-Clause`, see `LICENSE.md`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhywan%2Fcode-tour-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhywan%2Fcode-tour-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhywan%2Fcode-tour-rs/lists"}