{"id":9165,"date":"2022-02-14T18:52:54","date_gmt":"2022-02-14T18:52:54","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=9165"},"modified":"2022-02-14T18:52:54","modified_gmt":"2022-02-14T18:52:54","slug":"publishing-my-first-rust-library-to-crates-io","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/publishing-my-first-rust-library-to-crates-io\/","title":{"rendered":"Publishing my first Rust library to crates.io"},"content":{"rendered":"<p>As part of my end of 2021 project, I rewrote my F# units of measurement converters to a format which allowed me to code generate a bunch of libraries in different languages, currently including the original F#, C# (both idiomatic to their language), Java, Python, Swift, TypeScript and Rust. <\/p>\n<p>I&#8217;ve got the F# and C# ones available on nuget and the TypeScript on npmjs, I wanted to try to get the Rust library onto crates.io.<\/p>\n<p>How do we do this?<\/p>\n<ul>\n<li>First off, check if your package name is available on crates.io, if it is then you&#8217;ll need to change your name. Rust creates do not support namespaces so you cannot reuse an existing name but prefix with your company or whatever<\/li>\n<li>Load up https:\/\/crates.io\/ and create an account, I think using GitHub to login was the only option, so that&#8217;s what I did<\/li>\n<li>Ensure you have an email within your profile page and that it&#8217;s verified<\/li>\n<li>You can go to the API Tokens page and create a new token and a name for the token &#8211; you&#8217;ll need to copy the API token for the publish step (and keep it for further publishes unless you wish to revoke and regenerate &#8211; obviously not too useful in CI. If you set the environment variable CARGO_REGISTRY_TOKEN to the token then cargo will use it from there.<\/li>\n<li>Ensure your code is committed (if you&#8217;re using source control) or you can always specify the <em>&#8211;allow-dirty<\/em> option if you prefer not to commit changes<\/li>\n<li>Ensure you lib.rs has the correct version for your library setup. Semantic versioning is expected, hence you can use <em>-alpha<\/em> or the likes on your version<\/li>\n<li>Now run\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo login abcdefghijklmnopqrstuvwxyz\r\n<\/pre>\n<p>replacing <em>abcdefghijklmnopqrstuvwxyz<\/em> with your API token<\/li>\n<li>Next run\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncargo publish\r\n<\/pre>\n<\/li>\n<\/ul>\n<p>If all the above steps went well you can now search crates.io for your library.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of my end of 2021 project, I rewrote my F# units of measurement converters to a format which allowed me to code generate a bunch of libraries in different languages, currently including the original F#, C# (both idiomatic to their language), Java, Python, Swift, TypeScript and Rust. I&#8217;ve got the F# and C# [&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":[323,191],"tags":[],"class_list":["post-9165","post","type-post","status-publish","format-standard","hentry","category-crates","category-rust"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9165","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=9165"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9165\/revisions"}],"predecessor-version":[{"id":9167,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9165\/revisions\/9167"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}