{"id":188,"date":"2025-08-21T17:40:07","date_gmt":"2025-08-22T00:40:07","guid":{"rendered":"https:\/\/www.rusttutorial.com\/?page_id=188"},"modified":"2025-08-21T20:38:25","modified_gmt":"2025-08-22T03:38:25","slug":"rust-struct","status":"publish","type":"page","link":"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/","title":{"rendered":"Rust Struct"},"content":{"rendered":"\n<p>In this tutorial, you&#8217;ll learn how to create your own data types with Rust structs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='what-is-a-struct'>What is a Struct? <a href=\"#what-is-a-struct\" class=\"anchor\" id=\"what-is-a-struct\" title=\"Anchor for What is a Struct?\">#<\/a><\/h2>\n\n\n\n<p>A <strong>struct<\/strong> (short for \u201cstructure\u201d) is a way to group related data together under one name. Think of it like a <strong>blueprint<\/strong> for making objects.<\/p>\n\n\n\n<p>In other languages, structs are similar to <strong>classes without methods<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='defining-a-struct'>Defining a Struct <a href=\"#defining-a-struct\" class=\"anchor\" id=\"defining-a-struct\" title=\"Anchor for Defining a Struct\">#<\/a><\/h2>\n\n\n\n<p>Here\u2019s how you define a struct:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Rust\" data-shcb-language-slug=\"rust\"><span><code class=\"hljs language-rust\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">struct<\/span> <span class=\"hljs-title\">User<\/span><\/span> {\n    username: <span class=\"hljs-built_in\">String<\/span>,\n    email: <span class=\"hljs-built_in\">String<\/span>,\n    sign_in_count: <span class=\"hljs-built_in\">u64<\/span>,\n    active: <span class=\"hljs-built_in\">bool<\/span>,\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Rust<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">rust<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this struct:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A <code>User<\/code> has a <code>username<\/code> (a <code>String<\/code>).<\/li>\n\n\n\n<li>An <code>email<\/code> (a <code>String<\/code>).<\/li>\n\n\n\n<li>A <code>sign_in_count<\/code> (a <code>u64<\/code> number).<\/li>\n\n\n\n<li>An <code>active<\/code> flag (a <code>bool<\/code>).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='creating-a-struct-instance'>Creating a Struct Instance <a href=\"#creating-a-struct-instance\" class=\"anchor\" id=\"creating-a-struct-instance\" title=\"Anchor for Creating a Struct Instance\">#<\/a><\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Rust\" data-shcb-language-slug=\"rust\"><span><code class=\"hljs language-rust\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">fn<\/span> <span class=\"hljs-title\">main<\/span><\/span>() {\n    <span class=\"hljs-keyword\">let<\/span> user1 = User {\n        username: <span class=\"hljs-built_in\">String<\/span>::from(<span class=\"hljs-string\">\"alice\"<\/span>),\n        email: <span class=\"hljs-built_in\">String<\/span>::from(<span class=\"hljs-string\">\"alice@rusttutorial.com\"<\/span>),\n        sign_in_count: <span class=\"hljs-number\">1<\/span>,\n        active: <span class=\"hljs-literal\">true<\/span>,\n    };\n\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"Username: {}\"<\/span>, user1.username);\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"email: {}\"<\/span>, user1.email);\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"sign_in_count: {}\"<\/span>, user1.sign_in_count);\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"active: {}\"<\/span>, user1.active);\n}\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">struct<\/span> <span class=\"hljs-title\">User<\/span><\/span> {\n    username: <span class=\"hljs-built_in\">String<\/span>,\n    email: <span class=\"hljs-built_in\">String<\/span>,\n    sign_in_count: <span class=\"hljs-built_in\">u64<\/span>,\n    active: <span class=\"hljs-built_in\">bool<\/span>,\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Rust<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">rust<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTTP\" data-shcb-language-slug=\"http\"><span><code class=\"hljs language-http\"><span class=\"hljs-attribute\">Username<\/span>: alice\n<span class=\"hljs-attribute\">email<\/span>: alice@rusttutorial.com\n<span class=\"hljs-attribute\">sign_in_count<\/span>: 1\n<span class=\"hljs-attribute\">active<\/span>: true<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTTP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">http<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This creates a <code>User<\/code> instance called <code>user1<\/code>. You can access fields using <strong>dot notation<\/strong> (<code>user1.username<\/code>).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='mutating-a-struct'>Mutating a Struct <a href=\"#mutating-a-struct\" class=\"anchor\" id=\"mutating-a-struct\" title=\"Anchor for Mutating a Struct\">#<\/a><\/h2>\n\n\n\n<p>By default, structs are immutable. To change fields, declare it as <code>mut<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Rust\" data-shcb-language-slug=\"rust\"><span><code class=\"hljs language-rust\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">fn<\/span> <span class=\"hljs-title\">main<\/span><\/span>() {\n    <span class=\"hljs-keyword\">let<\/span> <span class=\"hljs-keyword\">mut<\/span> user1 = User {\n        username: <span class=\"hljs-built_in\">String<\/span>::from(<span class=\"hljs-string\">\"bob\"<\/span>),\n        email: <span class=\"hljs-built_in\">String<\/span>::from(<span class=\"hljs-string\">\"bob@example.com\"<\/span>),\n        sign_in_count: <span class=\"hljs-number\">1<\/span>,\n        active: <span class=\"hljs-literal\">true<\/span>,\n    };\n\n    user1.email = <span class=\"hljs-built_in\">String<\/span>::from(<span class=\"hljs-string\">\"new_email@rusttutorial.com\"<\/span>);\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"Updated email: {}\"<\/span>, user1.email);\n}\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">struct<\/span> <span class=\"hljs-title\">User<\/span><\/span> {\n    username: <span class=\"hljs-built_in\">String<\/span>,\n    email: <span class=\"hljs-built_in\">String<\/span>,\n    sign_in_count: <span class=\"hljs-built_in\">u64<\/span>,\n    active: <span class=\"hljs-built_in\">bool<\/span>,\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Rust<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">rust<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='using-struct-update-syntax'>Using Struct Update Syntax <a href=\"#using-struct-update-syntax\" class=\"anchor\" id=\"using-struct-update-syntax\" title=\"Anchor for Using Struct Update Syntax\">#<\/a><\/h2>\n\n\n\n<p>If you want to create a new struct based on an existing one:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Rust\" data-shcb-language-slug=\"rust\"><span><code class=\"hljs language-rust\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">fn<\/span> <span class=\"hljs-title\">main<\/span><\/span>() {\n    <span class=\"hljs-keyword\">let<\/span> user1 = User {\n        username: <span class=\"hljs-built_in\">String<\/span>::from(<span class=\"hljs-string\">\"charlie\"<\/span>),\n        email: <span class=\"hljs-built_in\">String<\/span>::from(<span class=\"hljs-string\">\"charlie@rusttutorial.com\"<\/span>),\n        sign_in_count: <span class=\"hljs-number\">5<\/span>,\n        active: <span class=\"hljs-literal\">true<\/span>,\n    };\n\n    <span class=\"hljs-keyword\">let<\/span> user2 = User {\n        username: <span class=\"hljs-built_in\">String<\/span>::from(<span class=\"hljs-string\">\"dave\"<\/span>),\n        ..user1\n    };\n\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"user2 username: {}\"<\/span>, user2.username);\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"user2 email: {}\"<\/span>, user2.email);\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"user2 sign_in_count: {}\"<\/span>, user2.sign_in_count);\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"user2 active: {}\"<\/span>, user2.active);\n    \n}\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">struct<\/span> <span class=\"hljs-title\">User<\/span><\/span> {\n    username: <span class=\"hljs-built_in\">String<\/span>,\n    email: <span class=\"hljs-built_in\">String<\/span>,\n    sign_in_count: <span class=\"hljs-built_in\">u64<\/span>,\n    active: <span class=\"hljs-built_in\">bool<\/span>,\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Rust<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">rust<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">user2<\/span> <span class=\"hljs-selector-tag\">username<\/span>: <span class=\"hljs-selector-tag\">dave<\/span>\n<span class=\"hljs-selector-tag\">user2<\/span> <span class=\"hljs-selector-tag\">email<\/span>: <span class=\"hljs-selector-tag\">charlie<\/span><span class=\"hljs-keyword\">@rusttutorial<\/span>.com\nuser2 sign_in_<span class=\"hljs-attribute\">count:<\/span> <span class=\"hljs-number\">5<\/span>\nuser2 <span class=\"hljs-attribute\">active:<\/span> true<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the <code>..user1<\/code> copies the remaining fields from <code>user1<\/code>.<\/p>\n\n\n\n<p>Note: <code>user1<\/code> can no longer be used after this, since ownership of its fields has moved to <code>user2<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='tuple-structs'>Tuple Structs <a href=\"#tuple-structs\" class=\"anchor\" id=\"tuple-structs\" title=\"Anchor for Tuple Structs\">#<\/a><\/h2>\n\n\n\n<p>Structs can also look like <a href=\"https:\/\/www.rusttutorial.com\/rust-tutorial\/tuple-structs-and-unit-structs\/#tuple-structs\">tuples<\/a> but with names:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Rust\" data-shcb-language-slug=\"rust\"><span><code class=\"hljs language-rust\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">struct<\/span> <span class=\"hljs-title\">Color<\/span><\/span>(<span class=\"hljs-built_in\">i32<\/span>, <span class=\"hljs-built_in\">i32<\/span>, <span class=\"hljs-built_in\">i32<\/span>);\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">fn<\/span> <span class=\"hljs-title\">main<\/span><\/span>() {\n    <span class=\"hljs-keyword\">let<\/span> black = Color(<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">0<\/span>);\n    <span class=\"hljs-built_in\">println!<\/span>(<span class=\"hljs-string\">\"Black color: {}, {}, {}\"<\/span>, black.<span class=\"hljs-number\">0<\/span>, black.<span class=\"hljs-number\">1<\/span>, black.<span class=\"hljs-number\">2<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Rust<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">rust<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fields are accessed by <strong>index<\/strong> instead of name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='unit-like-structs'>Unit-Like Structs <a href=\"#unit-like-structs\" class=\"anchor\" id=\"unit-like-structs\" title=\"Anchor for Unit-Like Structs\">#<\/a><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.rusttutorial.com\/rust-tutorial\/tuple-structs-and-unit-structs\/#unit-structs\">Structs with <strong>no fields<\/strong><\/a> are valid too:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Rust\" data-shcb-language-slug=\"rust\"><span><code class=\"hljs language-rust\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">struct<\/span> <span class=\"hljs-title\">Marker<\/span><\/span>;\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">fn<\/span> <span class=\"hljs-title\">main<\/span><\/span>() {\n    <span class=\"hljs-keyword\">let<\/span> _m = Marker;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Rust<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">rust<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>These are useful for traits or situations where you just need a \u201ctype marker.\u201d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Structs group related data<\/strong> into one custom type.<\/li>\n\n\n\n<li>Use <strong>dot notation<\/strong> to access fields.<\/li>\n\n\n\n<li>Use <code>mut<\/code> to make them mutable.<\/li>\n\n\n\n<li><strong>Struct update syntax<\/strong> helps reuse data.<\/li>\n\n\n\n<li>Rust also has <strong>tuple structs<\/strong> and <strong>unit-like structs<\/strong>.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<div class=\"wth-question\">Was this Helpful ?<\/div>\n\t<div class=\"wth-thumbs\">\n\t\t<button\n\t\t\tdata-post=\"188\"\n\t\t\tdata-post-url=\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/\"\n\t\t\tdata-post-title=\"Rust Struct\"\n\t\t\tdata-response=\"1\"\n\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t>\n\t\t\t<svg\n\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\tfill=\"none\"\n\t\t\t\tstroke=\"currentColor\"\n\t\t\t\tstroke-width=\"2\"\n\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t>\n\t\t\t\t<path\n\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t><\/path>\n\t\t\t<\/svg>\n\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t<\/button>\n\n\t\t<button\n\t\t\tdata-response=\"0\"\n\t\t\tdata-post=\"188\"\n\t\t\tdata-post-url=\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/\"\n\t\t\tdata-post-title=\"Rust Struct\"\n\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t>\n\t\t\t<svg\n\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\tfill=\"none\"\n\t\t\t\tstroke=\"currentColor\"\n\t\t\t\tstroke-width=\"2\"\n\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t>\n\t\t\t\t<path\n\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t><\/path>\n\t\t\t<\/svg>\n\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t<\/button>\n\t<\/div>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to create your own data types with Rust structs.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":9,"menu_order":22,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-188","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Rust Struct<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn how to create your own data types with Rust structs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Rust Struct\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn how to create your own data types with Rust structs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/\" \/>\n<meta property=\"og:site_name\" content=\"Rust Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-22T03:38:25+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/\",\"url\":\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/\",\"name\":\"Rust Struct\",\"isPartOf\":{\"@id\":\"https:\/\/www.rusttutorial.com\/#website\"},\"datePublished\":\"2025-08-22T00:40:07+00:00\",\"dateModified\":\"2025-08-22T03:38:25+00:00\",\"description\":\"In this tutorial, you'll learn how to create your own data types with Rust structs.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.rusttutorial.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Rust Tutorial\",\"item\":\"https:\/\/www.rusttutorial.com\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Rust Struct\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.rusttutorial.com\/#website\",\"url\":\"https:\/\/www.rusttutorial.com\/\",\"name\":\"Rust Tutorial\",\"description\":\"Learn Rust Programming from Scratch\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.rusttutorial.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Rust Struct","description":"In this tutorial, you'll learn how to create your own data types with Rust structs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/","og_locale":"en_US","og_type":"article","og_title":"Rust Struct","og_description":"In this tutorial, you'll learn how to create your own data types with Rust structs.","og_url":"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/","og_site_name":"Rust Tutorial","article_modified_time":"2025-08-22T03:38:25+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/","url":"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/","name":"Rust Struct","isPartOf":{"@id":"https:\/\/www.rusttutorial.com\/#website"},"datePublished":"2025-08-22T00:40:07+00:00","dateModified":"2025-08-22T03:38:25+00:00","description":"In this tutorial, you'll learn how to create your own data types with Rust structs.","breadcrumb":{"@id":"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.rusttutorial.com\/rust-tutorial\/rust-struct\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.rusttutorial.com\/"},{"@type":"ListItem","position":2,"name":"Rust Tutorial","item":"https:\/\/www.rusttutorial.com\/"},{"@type":"ListItem","position":3,"name":"Rust Struct"}]},{"@type":"WebSite","@id":"https:\/\/www.rusttutorial.com\/#website","url":"https:\/\/www.rusttutorial.com\/","name":"Rust Tutorial","description":"Learn Rust Programming from Scratch","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.rusttutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/pages\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":5,"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/pages\/188\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/pages\/188\/revisions\/242"}],"up":[{"embeddable":true,"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/pages\/9"}],"wp:attachment":[{"href":"https:\/\/www.rusttutorial.com\/wp-json\/wp\/v2\/media?parent=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}