DEV Community

Marco Ieni
Marco Ieni

Posted on • Originally published at marcoieni.com on

Create an amazing Rust GitHub project in no time

Introduction

Expectations on open source projects are becoming higher and higher everyday.If a project is not well documented and it doesn't have a test suite and a continuousintegration environment, it is very unlikely that it will be taken seriously bythe community.

Luckily for us, the tools to create high quality projectsare becoming better and better at the same time, too.

For example, rust provides:

  • the cargo build system which includes built-in support for tests and documentation

  • clippy static code analyzer

  • rustfmt auto formatting tool

These tools are well established and they are used by all the relevant rust projects.The rust ecosystem, in fact, is really homogeneous, in the sense that the way youbuild, test, run and deploy a certain application/library is very standard.

Therefore, when you are creating a new project, it's really likely that you canrecycle documentation and CI steps from your older projects or other bigger rustprojects out there..which is great, but as my java professor taught me:

if you are copying and pasting several times, you are almost surely doing it wrong!

And that's exactly what I was doing..In fact, every time I had to create a new GitHub project, I was using the goodcopying and pasting technique on:

  • the set of markdownfiles that GitHub asks you to fill, such as CONTRIBUTING.md, CHANGELOG.md, CODE_OF_CONDUCT.md, issueand pull request templates, and most importantly the README.md!

  • files needed to setup the CI environment, most of the time GitHub actions, specifically.

Now, because of the standard tooling that rust provides, copying and pasting worksreally well on these files, because as we said, what works for one project will almost workfor another one. But we can do better than this..

cargo generate

In order to avoid copying and pasting, there is the cargo generate tool, which isdescribed as:

a developer tool to help you get up and running quickly with a new Rust project by leveraging a pre-existing git repository as a template.

This means that you can setup a template repository, with all the files youneed and you ask cargo generate to create a project starting from thistemplate, by replacing project name and authors (and username soon?) with yours.

After using this tool to create some rust embedded projects with really littleeffort, I immediately appreciated its power and so during these days I decidedto use it to create a new template that makes me skip the copying and pasting phase ofcreating a new rust project hosted on github.

Rust GitHub Template

I have described the Rust GitHub Template on a website, where I describedits features and instructions onhow to use it to create a new rust project.

In short, it allows you to create a new rust project with documentation andGitHub actions such as automatic security checks, CI and CD already set up byonly specifying project name and GitHub username.You can see an example project generated by this template here.

As the Rust GitHub Template website states:

Stop copy pasting tons of markdown and yaml files each time you start a new rust project. Let’s write them only once, together!

Thanks, and I hope you enjoy using Rust GitHub Template!

Discussion (0)