From 325dbf2a6e1ce587ae1b1fb5c877d7414759b30a Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Mon, 2 May 2022 22:43:09 +0100 Subject: [PATCH] Begin writing getting started guide --- data/editors.json | 32 ++++++++ src/main.rs | 1 + src/routes.rs | 1 + src/routes/getting_started/guide.rs | 55 +++++++++++++ src/routes/getting_started/mod.rs | 1 + static/index.css | 15 ++++ templates/routes/getting_started/guide.html | 90 +++++++++++++++++++++ 7 files changed, 195 insertions(+) create mode 100644 data/editors.json create mode 100644 src/routes/getting_started/guide.rs create mode 100644 src/routes/getting_started/mod.rs create mode 100644 templates/routes/getting_started/guide.html diff --git a/data/editors.json b/data/editors.json new file mode 100644 index 0000000..9a415d2 --- /dev/null +++ b/data/editors.json @@ -0,0 +1,32 @@ +[ + { + "name": "VS Code", + "url": "https://code.visualstudio.com/", + "editor_plugins": "Rust Analyzer (note: avoid the \"Rust\" plugin. It is in the process of being deprecated and has a number of issues that are solved in the new Rust Analyzer plugin)", + "notes": "Generally recommended" + }, + { + "name": "Intellij/CLion", + "url": "https://www.jetbrains.com/rust/", + "editor_plugins": "Rust Plugin", + "notes": "Well supported. A good option if you like Intellij products." + }, + { + "name": "Sublime Text", + "url": "https://www.sublimetext.com/", + "editor_plugins": "sublime-lsp and lsp-rust-analyzer plugins", + "notes": "Well supported. A good option if you like Intellij products." + }, + { + "name": "Vim/NeoVim", + "url": "https://neovim.io/", + "editor_plugins": "TBD", + "notes": "If you know you know. Not recommended for beginners." + }, + { + "name": "Emacs", + "url": "https://www.gnu.org/software/emacs/", + "editor_plugins": "TBD", + "notes": "If you know you know. Not recommended for beginners." + } +] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index cd5ce45..78532a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,7 @@ async fn main() { .route("/", get(|| async { Redirect::to("/crates") })) .route("/users", post(routes::users::create::run)) .route("/crates", get(routes::crates::list::run)) + .route("/getting-started", get(routes::getting_started::guide::run)) .nest("/static", static_file_service) .layer(TraceLayer::new_for_http()); diff --git a/src/routes.rs b/src/routes.rs index 6b9ac16..4d96b46 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,5 +1,6 @@ pub mod users; pub mod crates; +pub mod getting_started; // basic handler that responds with a static string pub async fn index() -> &'static str { diff --git a/src/routes/getting_started/guide.rs b/src/routes/getting_started/guide.rs new file mode 100644 index 0000000..2332b4d --- /dev/null +++ b/src/routes/getting_started/guide.rs @@ -0,0 +1,55 @@ +use axum::{ + http::StatusCode, + response::{ IntoResponse, Html }, +}; +use serde::{Serialize, Deserialize}; +use serde_json; +use tera::Context; +use crate::templates::{ TERA, TocSection, TocSubSection }; + +pub(crate) async fn run() -> impl IntoResponse { + + // Load editor data + let data_file_contents : &str = include_str!("../../../data/editors.json"); + let editors : Vec = serde_json::from_str(&data_file_contents).unwrap(); + + let toc_sections = vec![ + TocSection { name: "Installation".into(), slug: "installation".into(), subsections: vec![ + TocSubSection { name: "Rustup".into(), slug: "cargo-rustc".into() }, + TocSubSection { name: "Editor Setup".into(), slug: "editor-setup".into() }, + TocSubSection { name: "Cargo Plugins".into(), slug: "cargo-plugins".into() }, + ]}, + TocSection { name: "Learning Resources".into(), slug: "learning-resources".into(), subsections: vec![ + TocSubSection { name: "Books".into(), slug: "books".into() }, + TocSubSection { name: "Crate Discovery".into(), slug: "crate-discovery".into() }, + TocSubSection { name: "Community Updates".into(), slug: "community-updates".into() }, + TocSubSection { name: "Asking for help".into(), slug: "help".into() }, + ]} + ]; + + // Render template + let mut context = Context::new(); + context.insert("editors", &editors); + context.insert("toc_sections", &toc_sections); + let rendered = TERA.render("routes/getting_started/guide.html", &context); + + // Handle template rendering errors + let res = match rendered { + Ok(res) => (StatusCode::OK, Html(res)), + Err(err) => { + tracing::debug!("Error: {:?}", err); + (StatusCode::INTERNAL_SERVER_ERROR, Html(format!("
{:#?}
", err))) + } + }; + + // Return response + (StatusCode::OK, res) +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +struct Editor { + name: String, + url: String, + editor_plugins: String, + notes: String, +} \ No newline at end of file diff --git a/src/routes/getting_started/mod.rs b/src/routes/getting_started/mod.rs new file mode 100644 index 0000000..57d4406 --- /dev/null +++ b/src/routes/getting_started/mod.rs @@ -0,0 +1 @@ +pub mod guide; \ No newline at end of file diff --git a/static/index.css b/static/index.css index 5bb6552..3e4eb9c 100644 --- a/static/index.css +++ b/static/index.css @@ -105,6 +105,21 @@ p.introduction { color: #666; } +p, li { + color: #666; + line-height: 1.35; +} + +#content ul { + max-width: 800px; + padding-left: 48px; +} + +#content li { + margin-bottom: 12px; + padding-left: 12px; +} + section { margin-bottom: 24px; } diff --git a/templates/routes/getting_started/guide.html b/templates/routes/getting_started/guide.html new file mode 100644 index 0000000..e92af51 --- /dev/null +++ b/templates/routes/getting_started/guide.html @@ -0,0 +1,90 @@ +{% extends "base.html" %} +{% import "macros/toc.html" as toc %} +{% block title %}Crate List{% endblock title %} + +{% block head %} + {{ super() }} + +{% endblock head %} + +{% block main %} + +
+ + {{ toc::left_sidebar(sections=toc_sections) }} + + +
+ +
+

Installation

+

+
+

Rustup

+

+ Compared to other programming languages such as Python and Go, Rust's standard library is very small, including only core data structures in the standard library with all other functionality farmed out to 3rd party ecosystem crates, and a common complaint from new Rust developers is that they don't know where to start: which crates they ought to use and which crates they ought to trust. +

+
+ +
+

Learning Resources

+

+ +
+

Books

+
    +
  • + The Rust Programming Language + The official rust-lang book. Aimed at those with experience in another programming language but not + necessarily a low-level one. This is also the best option if you are trying to learn Rust as your first programming language. Freely available online (a print version is also available) +
  • +
  • + Programming Rust + Another book aimed at those with experience in another programming language, but not + necessarily a low-level one. While the official book above has a stellar reputation, this one has a reputation for being even better, + diving deeper and giving a more thorough introduction to the language. The downside being it's not free. +
  • +
  • + Rust in action + This one has a slightly different focus, and is more suited to the more experienced developer with some grasp of CS theory, or those coming from a background in C or C++. It takes the reader through some relatively advanced projects including a CPU emulator, database, and an OS kernel. +
  • +
  • + Rust for Rustaceans + A more advanced book that dives into some of the more involved parts of Rust. Not suitable for a complete beginner (even if they have experience in other languages). Best read after you have already learnt some basic Rust through one or more of the other resources. +
  • +
+ +
+ +
+ +
+
+ +{% endblock main %} + +{% block footer %} + +{% endblock footer %}