{"id":9091,"date":"2022-03-16T21:01:51","date_gmt":"2022-03-16T21:01:51","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=9091"},"modified":"2022-03-16T21:01:51","modified_gmt":"2022-03-16T21:01:51","slug":"cargo","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/cargo\/","title":{"rendered":"Cargo"},"content":{"rendered":"<p>As part of a little project I&#8217;m working on, I&#8217;m back playing within Rust. <\/p>\n<p>Whilst we can use <em>rustc<\/em> to build our code we&#8217;re more likely to use the build and package management application <em>cargo<\/em>. Let&#8217;s take a look at the core features of using <em>cargo<\/em>.<\/p>\n<p><strong>What version are you running?<\/strong><\/p>\n<p>To find the version of cargo, simply type<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo --version\r\n<\/pre>\n<p><strong>Creating a new project<\/strong><\/p>\n<p>Cargo can be used to create a minimal project which will include the .toml configuration file and the code will be written to a src folder. Cargo expects a specific layout of configuration and source as well as writing the building artifacts to the target folder.<\/p>\n<p>To generate a minimal application run the following (replacing app_name with your application name)<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo new app_name\r\n<\/pre>\n<p>We can also use cargo to create a minimal library using the &#8211;lib switch<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo new lib_name --lib\r\n<\/pre>\n<p><strong>Building our project<\/strong><\/p>\n<p>To build the project artifacts, run the following from the root of your application\/library<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo build\r\n<\/pre>\n<p>This command will create the binaries in the target folder. This is (by default) a debug build, to create a release build ass the &#8211;release switch i.e.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo build --release\r\n<\/pre>\n<p><strong>Running our project<\/strong><\/p>\n<p>In the scenarios where we&#8217;ve generated an executable, then we can run the application by cd-ing into the target folder and running the .exe or via cargo we use<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo run\r\n<\/pre>\n<p><strong>Check your build<\/strong><\/p>\n<p>In some cases, where you are not really interested in generating an executable (for example) you can run the <em>check<\/em> command which will simply verify your code is valid &#8211; this will likely be faster than generating the executable and is useful where you just want to ensure your code will build<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo check\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As part of a little project I&#8217;m working on, I&#8217;m back playing within Rust. Whilst we can use rustc to build our code we&#8217;re more likely to use the build and package management application cargo. Let&#8217;s take a look at the core features of using cargo. What version are you running? To find the version [&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":[322,191],"tags":[],"class_list":["post-9091","post","type-post","status-publish","format-standard","hentry","category-cargo","category-rust"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9091","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=9091"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9091\/revisions"}],"predecessor-version":[{"id":9288,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9091\/revisions\/9288"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}