{
    "componentChunkName": "component---src-templates-spotlight-tsx",
    "path": "/spotlights/what-is-rust.md",
    "result": {"data":{"file":{"relativePath":"what-is-rust.md","post":{"body":"var _excluded = [\"components\"];\nfunction _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }\nfunction _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }\nfunction _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }\n/* @jsxRuntime classic */\n/* @jsx mdx */\n\nvar _frontmatter = {\n  \"authors\": [\"Fox#0001\"],\n  \"created_at\": \"2018/10/08\",\n  \"title\": \"What is Rust?\"\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n    props = _objectWithoutProperties(_ref, _excluded);\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h2\", {\n    \"id\": \"what-is-rust\"\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#what-is-rust\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"What is Rust?\"), mdx(\"p\", null, \"\\\"Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.\\\"\\nIn other terms, Rust is a language that offers the performance of C or C++ along with some higher level constructs\\nthat let the compiler figure out whether or not your code is safe.\\nBut what is safe? Safe here means that your program shouldn't leak memory, access uninitialised or undefined\\nmemory, or yield odd results because of race conditions in your code. Rust, similar to C++, offers what\\nare called \\\"Zero-cost\\\" abstractions, which in essence means that the idiomatic/ pretty way of writing a piece\\nof code will be as performant as writing your own code.\"), mdx(\"h2\", {\n    \"id\": \"how-is-rust-safe\"\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#how-is-rust-safe\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"How is Rust safe?\"), mdx(\"p\", null, \"Rust adds an extra layer of safety by having a concept of ownership at the type level, and by\\nstrongly distinguishing mutability over immutability. By keeping track of where a resource is owned,\\nthe compiler can figure out at compile time when that resource can safely be destroyed, thus preventing\\na large class of bugs related to manual memory management.\\nRust also uses this ownership system to keep track of resource management across threads, thus preventing\\ndata races.\"), mdx(\"p\", null, \"Like C and C++, Rust doesn't have any garbage collection, but unlike C, and to a lesser extent C++,\\nRust doesn't have manual memory management. Because of this ownership system, the compiler figures\\nout when to safely drop resources. Unlike in C, where you could leak memory by forgetting to free\\nsome resource, or crash your program by using memory that has already been freed, Rust avoids errors like\\nthese by keeping track of who owns what resource at compile time.\"), mdx(\"h2\", {\n    \"id\": \"what-high-level-constructs-does-rust-offer\"\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#what-high-level-constructs-does-rust-offer\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"What high level constructs does Rust offer?\"), mdx(\"p\", null, \"Rust comes with a very good standard library, if you're not building on an embedded platform, of course.\\nThe standard library allows you to work with vectors and arrays using concise .maps and .filters instead\\nof your standard for loop. In addition to constructs provided by the standard library, the language itself\\nhas common modern language features, such as modules, structs, and anonymous functions (closures).\\nOne of the more unique Rust features is Traits, which are like Interfaces, but in reverse. Instead of a Struct\\ninheriting from an Interface when it's defined, a Trait is defined after a Struct, and then the implementation of\\nthat Trait for the Struct may be defined. This allows you to create new interfaces and have pre-existing types\\nadhere to them. This offers a bit more extensibility than the traditional interface system.\"), mdx(\"p\", null, \"Another newer feature Rust has is pattern matching, which allows you to match not and branch code not only\\non the simple value of data, but also on its structure. For example instead of matching on a simple integer value,\\nyou can match on a hashmap with a certain value at a certain key.\"), mdx(\"p\", null, \"One of the external aspects that makes the language easy to work with is the build tool \\\"Cargo\\\". Cargo\\nmakes fetching dependencies for a project and building a project a breeze!\"), mdx(\"h2\", {\n    \"id\": \"where-do-i-get-rust\"\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#where-do-i-get-rust\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Where do I get Rust?\"), mdx(\"p\", null, \"Installation instructions can be found here: \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://www.rust-lang.org/en-US/install.html\"\n  }, \"https://www.rust-lang.org/en-US/install.html\")), mdx(\"h2\", {\n    \"id\": \"where-do-i-learn-more\"\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#where-do-i-learn-more\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Where do I learn more?\"), mdx(\"p\", null, \"Rust has a great book for learning the language, that can be found here (online book): \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://doc.rust-lang.org/book/second-edition/index.html\"\n  }, \"https://doc.rust-lang.org/book/second-edition/index.html\")), mdx(\"h2\", {\n    \"id\": \"code-examples\"\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#code-examples\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Code Examples\"), mdx(\"h3\", {\n    \"id\": \"hello-world\"\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#hello-world\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Hello World\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-rust\"\n  }, \"fn main() {\\n    println!(\\\"Hello World!\\\");\\n}\\n\")), mdx(\"h3\", {\n    \"id\": \"pattern-matching-example\"\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#pattern-matching-example\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Pattern Matching Example\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-rust\"\n  }, \"fn main() {\\n    let p = Point { x: 0, y: 7 };\\n\\n    match p {\\n        Point { x, y: 0 } => println!(\\\"On the x axis at {}\\\", x),\\n        Point { x: 0, y } => println!(\\\"On the y axis at {}\\\", y),\\n        Point { x, y } => println!(\\\"On neither axis: ({}, {})\\\", x, y),\\n    }\\n}\\n\")), mdx(\"h3\", {\n    \"id\": \"sum-of-squared-odd-numbers-under-1000\"\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#sum-of-squared-odd-numbers-under-1000\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Sum of Squared Odd Numbers under 1000\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-rust\"\n  }, \"fn is_odd(n: u32) -> bool {\\n    n % 2 == 1\\n}\\n\\nfn main() {\\n    println!(\\\"Find the sum of all the squared odd numbers under 1000\\\");\\n    let upper = 1000;\\n\\n    // Imperative approach\\n    // Declare accumulator variable\\n    let mut acc = 0;\\n    // Iterate: 0, 1, 2, ... to infinity\\n    for n in 0.. {\\n        // Square the number\\n        let n_squared = n * n;\\n\\n        if n_squared >= upper {\\n            // Break loop if exceeded the upper limit\\n            break;\\n        } else if is_odd(n_squared) {\\n            // Accumulate value, if it's odd\\n            acc += n_squared;\\n        }\\n    }\\n    println!(\\\"imperative style: {}\\\", acc);\\n\\n    // Functional approach\\n    let sum_of_squared_odd_numbers: u32 =\\n        (0..).map(|n| n * n)                             // All natural numbers squared\\n             .take_while(|&n_squared| n_squared < upper) // Below upper limit\\n             .filter(|&n_squared| is_odd(n_squared))     // That are odd\\n             .fold(0, |acc, n_squared| acc + n_squared); // Sum them\\n\\n    println!(\\\"functional style: {}\\\", sum_of_squared_odd_numbers);\\n}\\n\")), mdx(\"h3\", {\n    \"id\": \"traits-example\"\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#traits-example\",\n    \"aria-hidden\": true,\n    \"className\": \"anchor\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Traits Example\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-rust\"\n  }, \"pub trait Summary {\\n    fn summarize(&self) -> String;\\n}\\n\\npub struct NewsArticle {\\n    pub headline: String,\\n    pub location: String,\\n    pub author: String,\\n    pub content: String,\\n}\\n\\nimpl Summary for NewsArticle {\\n    fn summarize(&self) -> String {\\n        format!(\\\"{}, by {} ({})\\\", self.headline, self.author, self.location)\\n    }\\n}\\n\\npub struct Tweet {\\n    pub username: String,\\n    pub content: String,\\n    pub reply: bool,\\n    pub retweet: bool,\\n}\\n\\nimpl Summary for Tweet {\\n    fn summarize(&self) -> String {\\n        format!(\\\"{}: {}\\\", self.username, self.content)\\n    }\\n}\\n\\nfn main() {\\n    let tweet = Tweet {\\n        username: String::from(\\\"horse_ebooks\\\"),\\n        content: String::from(\\\"of course, as you probably already know, people\\\"),\\n        reply: false,\\n        retweet: false,\\n    };\\n\\n    // 1 new tweet: horse_ebooks: of course, as you probably already know, people\\n    println!(\\\"1 new tweet: {}\\\", tweet.summarize());\\n}\\n\")));\n}\n;\nMDXContent.isMDXComponent = true;","excerpt":"What is Rust? \"Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.\"\nIn other…","fields":{"authors":[{"name":"Fox","hash":"0001","avatar":"https://cdn.discordapp.com/embed/avatars/1.png"}]},"frontmatter":{"created_at":"2018/10/08"},"timeToRead":2}}},"pageContext":{"file":"what-is-rust.md","layout":"spotlights"}},
    "staticQueryHashes": ["1967409267","3753197437","63159454"]}