- Don’t use
"*"
dep version requirements. - Add
Cargo.lock
to version control. - Why read to string if you’re going to base64-encode and use
Vec<u8>
later anyway?
"*"
dep version requirements.Cargo.lock
to version control.Vec<u8>
later anyway?Here is an originally random list (using cargo tree --prefix=depth
) with some very loose logical grouping. Wide-scoped and well-known crates removed (some remaining are probably still known by most).
mime data-encoding percent-encoding textwrap unescape unicode-width scraper
arrayvec bimap bstr enum-iterator os_str_bytes pretty_assertions paste
clap_complete console indicatif shlex
lz4_flex mpeg2ts roxmltree speedy
aes base64 hex cbc sha1 sha2 rsa
reverse_geocoder trust-dns-resolver
signal-hook signal-hook-tokio
blocking
fs2
semver
snmalloc-rs
My quick notes which are tailored to beginners:
Option::ok_or_else()
and Result::map_err()
instead of let .. else
.let .. else
didn’t always exist. And you might find that some old timers are slightly triggered by it.Option
s as iterators (yes Option
s are iterators).?
operator and the Try
traitlet headers: HashMap = header_pairs
.iter()
.map(|line| line.split_once(":").unwrap())
.map(|(k, v)| (k.trim().to_string(), v.trim().to_string()))
.collect();
(Borken sanitization will probably butcher this code, good thing the problem will be gone in Lemmy 0.19)
Three tips here:
headers
will be returned as a struct field, the type of which is already known.collect()
itself. That may prove useful in other scenarios.Result
/Option
if the iterator items are Result
s/Option
s. So that .unwrap()
is not an ergonomic necessity 😉.into()
or .to_owned()
for &str => String
conversions.
http
crate is the compatibility layer used HTTP rust implementations. Check it out and maybe incorporate it into your
experimental/educational code.Alright, I will stop myself here.
Broken input sanitization probably.
Issue will thankfully no longer exist in the next lemmy release.
lemmy deleted everything between the “less than” character and “>”.
Lemmy also escaped the ampersands in their comment’s link 😉
Isn’t broken sanitization great!
Next Day Edit: Sorry. Forgot to use my Canadian Aboriginal syllabics again. Because apparently it’s too hard to admit HTML-sanitizing source markdown was wrong!
One thing that irks me in these articles is gauging the opinion of the “Rust community” through Reddit/HN/Lemmy😉/blogs… etc. I don’t think I’d be way off the mark when I say that these platforms mostly collectively reflect the thoughts of junior Rustaceans, or non-Rustaceans experimenting with Rust, with the latter being the loudest, especially if they are struggling with it!
And I disagree with the argument that poor standard library support is the major issue, although I myself had that thought before. It’s definitely current lack of language features that do introduce some annoyances. I do agree however that implicit coloring is not the answer (or an answer I want to ever see).
Take this simple code I was writing today. Ideally, I would have liked to write it in functional style:
async fn some_fn(&self) -> OptionᐸMyResᐸVecᐸu8ᐳᐳᐳ {
(bool_cond).then(|| async {
// ...
// res_op1().await?;
// res_op2().await?;
// ...
Ok(bytes)
})
}
But this of course doesn’t work because of the opaque type of the async block. Is that a serious hurdle? Obviously, it’s not:
async fn some_fn(&self) -> OptionᐸMyResᐸVecᐸu8ᐳᐳᐳ {
if !bool_cond {
return None;
}
let res = || async {
// ...
// res_op1()?;
// res_op2()?;
// ...
Ok(bytes)
};
Some(res().await)
}
And done. A productive Rustacean is hardly wasting time on this.
Okay, bool::then()
is not the best example. I’m just show-casing that it’s current language limitations, not stdlib ones, that are behind the odd async annoyance encountered. And the solution, I would argue, does not have to come in the form of implicit coloring.
Practically speaking, you don’t have to.
Your executor of choice should be doing tokio
compat for you, one way or another, so you don’t have to worry about it (e.g. async-global-executor with the tokio
feature).
async-std
is dead.
I would bad mouth Axum and Actix just because of the overhype. But then, the latter is powering this very platform, and the former is used in the federation crate examples 😉
So let me just say that I tried poem
and it got the job done for me. Rusty API. Decent documentation. And everything is in one crate. No books, extension crates, and tower
s of abstractions needed.
I try to avoid tokio
stuff in general for the same reason, although a compatible executor is unfortunately often required.
From your list, I use bat
, exa
and rg
.
delta (sometimes packaged as git-delta
) deserves a mention. I use it with this git configuration:
[core]
# --inspect-raw-lines=false fixes issue where some added lines appear in bold blue without green background
# default minus-style is 'normal auto'
pager = "delta --inspect-raw-lines=false --minus-style='syntax #400000' --plus-style='syntax #004000' --minus-emph-style='normal #a00000' --plus-emph-style='normal #00a000' --line-buffer-size=48 --max-line-distance=0.8"
[interactive]
diffFilter = "delta --inspect-raw-lines=false --color-only --minus-style='syntax #400000' --plus-style='syntax #004000' --minus-emph-style='normal #a00000' --plus-emph-style='normal #00a000' --line-buffer-size=48 --max-line-distance=0.8"
[delta]
navigate = true # use n and N to move between diff sections
light = false # set to true if you're in a terminal w/ a light background color (e.g. the default macOS terminal)
[merge]
conflictstyle = diff3
Still on 0.17.4 btw.
It might actually be a bug that the thread didn’t end up here as comments
If that’s the case, that’s a good bug in my book.
if you’ve been following us for a while you know we’re passionate about #Rust! 🦀
who’s “us”?
following where?
is there a reason to particularly care about ᐸwhoever you areᐳ
’s passion for Rust?
^ only meant half-seriously to point to the silliness of microblogging to a discussion community.
Note: the
ᐸᐳ
characters are Canadian Aboriginal syllabics because Lemmy devs haven’t fixed broken input sanitization yet.
This should be de-stickied. The instance appears to be receiving zero maintenance (still on 0.17.4, enough said).
While this is indeed paranoid and not well informed, I’m kind of appreciating… the GNU appreciation.
Makes a good change from all the hypernormalized Twitter/Mastadon non-coders, or self-proclaimed coders (the kind that uses terms like “imposter syndrome” every day), always bitching about how GNU was a mistake, and all it did was provide free labor for corporations, and how the FSF and Stallman are all kinds of bad and wrong.
Regarding
Cargo.lock
, the recommendation always was to include it in version control for application/binary crates, but not library ones. But tendencies changed over time to include it even for libraries. If arust-toolchain
file is tracked by version control, and is pinned to a specific stable release, thenCargo.lock
should definitely be tracked too [1][2].It’s strictly more information tracked, so there is no logical reason not to include it. There was this concern about people not being aware of
--locked
not being the default behaviour ofcargo install
, giving a false sense of security/reliability/reproducibility. But “false sense” is never a good technical argument in my book.Anyway, your crate is an application/binary one. And if you were to not change the
"*"
dependency version requirement, then it is almost guaranteed that building your crate will break in the future without trackingCargo.lock
;)