For my first not-completely-trivial Rust project, I decided to convert one of my smaller Python projects to Rust. It's a library for parsing GitHub URLs and "owner/repo" strings into objects that store the individual owner & repository name, with methods for reconstructing the various GitHub URL formats. Also included is a small command-line program for printing the owner & name of the GitHub repo for a local clone, optionally with all the various URLs as well.
The code: https://github.com/jwodder/ghrepo-rust
Aside from general comments, I'd like reviews to address the following:
-
Am I using
&str
vs.String
(and borrowing in general) properly & idiomatically? -
Should the tests be in
lib.rs
or intests/
? While I realize that, if you were to ask five different programmers about the difference between unit tests and integration tests, you'd get six different answers, the tests here really feel like unit tests to me; the only thing integration-like is that they only test the public behavior (not that there's much private behavior). -
Is the naming of
from_str_with_owner()
idiomatic? The only other way I thought of to implement this function was with a dedicatedDefaultOwner
struct with aparse(&str) -> GHRepo
method, but that seemed excessive. -
Should
LocalRepo
's constructors verify that the directory exists and/or is a Git repo? -
The API guidelines discourage the naming of getters with
get_*
, which initially led me to rename most of theLocalRepo
methods, e.g., changingget_current_branch()
to justcurrent_branch()
. However, on further reflection, these methods aren't getters, so I don't know whether it would be appropriate to give themget_*
names or not. -
Is it better to put
run()
andArguments
inlib.rs
(as recommended by ch.12.3 of The Rust Programming Language) or inmain.rs
, seeing as I don't see a reason to expose them to the general public? -
Should I keep
Cargo.lock
under version control or not? The Cargo FAQ says that binary crates should commit it and library crates shouldn't, but this is both a binary and a library. -
Are there any improvements I could make to the CI setup?
Thank you in advance.