{"id":7709,"date":"2019-11-21T21:20:41","date_gmt":"2019-11-21T21:20:41","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=7709"},"modified":"2019-11-21T21:20:41","modified_gmt":"2019-11-21T21:20:41","slug":"rust-constructors","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/rust-constructors\/","title":{"rendered":"Rust constructors"},"content":{"rendered":"<p>Rust doesn&#8217;t have the concept of a constructor in the sense of C++, C#, Java etc. You create new data structures by simply using the following syntax<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct Point {\r\n   x: i32,\r\n   y: i32\r\n}\r\n\r\nlet pt = Point { x: 10, y: 20 };\r\n<\/pre>\n<p>However, by convention you might create an <em>impl<\/em> to create\/initialize your structures. Rust code, by convention suggests such functions be named <em>new<\/em>. For example<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nimpl Point {\r\n    pub fn new() -&gt; Point {\r\n        Point {\r\n            x: 0, \r\n            y: 0\r\n        }\r\n    }\r\n}\r\n\r\nlet pt = Point::new();\r\n<\/pre>\n<p>Ofcourse, we might declare parameters\/arguments on the function just like any other functions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rust doesn&#8217;t have the concept of a constructor in the sense of C++, C#, Java etc. You create new data structures by simply using the following syntax struct Point { x: i32, y: i32 } let pt = Point { x: 10, y: 20 }; However, by convention you might create an impl to create\/initialize [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[191],"tags":[],"class_list":["post-7709","post","type-post","status-publish","format-standard","hentry","category-rust"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/7709","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=7709"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/7709\/revisions"}],"predecessor-version":[{"id":7722,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/7709\/revisions\/7722"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=7709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=7709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=7709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}