Skip to content

a quick sketch of some ideas#1

Closed
danieleades wants to merge 2 commits intoOverkillGuy:masterfrom
danieleades:some-ideas
Closed

a quick sketch of some ideas#1
danieleades wants to merge 2 commits intoOverkillGuy:masterfrom
danieleades:some-ideas

Conversation

@danieleades
Copy link
Contributor

No description provided.

use std::env;
use std::fs;
#![feature(seek_stream_len)]
#![warn(clippy::pedantic)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this enables pedantic lints when you run cargo clippy. It's not a bad way to learn Rust idioms (but as the name suggests, it can be quite pedantic!)

use std::fs;
#![feature(seek_stream_len)]
#![warn(clippy::pedantic)]
#![deny(missing_docs, missing_debug_implementations, clippy::all)]
Copy link
Contributor Author

@danieleades danieleades Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are more compiler flags. You may not want these, but there are loads more of this too if you want to enforce certain idioms in your codebase. these are some of my favourites

  • deny(missing_docs) - this will prevent your code from compiling if you have failed to document anything which is in your public API
  • deny(missing_debug_implementations) - prevent code from compiling if any struct is missing a Debug implementation (this prevents errors involving this type being printed nicely to console)
  • deny(clippy::all) - prevent compiling for any standard clippy lint. all the lints in this category are very sensible, so this is a good one to enforce

@danieleades
Copy link
Contributor Author

danieleades commented Feb 23, 2021

the iterator i've sketched here means you can operate without pulling the whole file into memory at once, but if you don't mind reading the whole file into memory you use either of the following to get 1024 byte chunks

depends on how big the files are, and how much you care about memory usage. (I would use the streaming iterator, feels a bit more 'Rusty')

OverkillGuy added a commit that referenced this pull request Feb 27, 2021
@OverkillGuy
Copy link
Owner

I adopted most of these, but have issues with the missing docs one, cannot find a good way to use it. See commit above

Also, running cargo clippy warns me about u64 -> f64 conversion issues, but doesn't provide alternatives or ways to shut it up?
I can't find a way to run a 0-warning policy in this repo like that.

Any ideas?

@danieleades
Copy link
Contributor Author

I adopted most of these, but have issues with the missing docs one, cannot find a good way to use it. See commit above

This lint is complaining that you don't have top-level documentation.

to comment a scope in rust you use a triple slash (///)
in order to add a comment to the enclosing scope you use (//!)

so if you add documentation comments to the top of the main.rs file, using the //! syntax, that adds documentation to the application itself. It's complaining that's missing.

Also, running cargo clippy warns me about u64 -> f64 conversion issues, but doesn't provide alternatives or ways to shut it up?
you can add a #[allow(clippy::...)] to allow a specific warning for a particular line or block
I can't find a way to run a 0-warning policy in this repo like that.

Any ideas?

i'll rebase this pull request and silence those lints

@danieleades
Copy link
Contributor Author

couple more tips-

structopt is way better than clap. It's a wrapper around clap that takes the calp 'stringly-typed' interface and gives you a strongly-typed struct.

It's so much better than Clap in fact that Clap 3.0 pulls structopt into the the clap repo itself and exports it as it's main interface. that version of clap is in beta, but it's pretty stable.

the extern crate PACKAGE lines are redundant since the 2018 edition of Rust. These can be removed. All your eternal dependencies are implicitly imported and are already in scope

@danieleades
Copy link
Contributor Author

ok the rebase was painful. see #2 instead

OverkillGuy added a commit that referenced this pull request Mar 20, 2021
Inspired by / stolen from PR #1

Not called ChunkIterator because a more specific "chunk iterator" will
be created next for converting text into chunk string content (base64
incl. prefix)
@OverkillGuy OverkillGuy mentioned this pull request Mar 21, 2021
@OverkillGuy
Copy link
Owner

Since we've adopted most of the recommendations in this PR (iterators ongoing in #20, lint and warnings as per #2, and the rest is spun off into its own PRs like #5, closing this as it completed its purpose.

Thanks again!

OverkillGuy added a commit that referenced this pull request Mar 28, 2021
Inspired by / stolen from PR #1

Not called ChunkIterator because a more specific "chunk iterator" will
be created next for converting text into chunk string content (base64
incl. prefix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants