Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some small refactorings #2305

Merged
merged 2 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions diesel/src/migration/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ impl fmt::Display for MigrationError {
f,
"Unable to find migrations directory in this directory or any parent directories."
),
MigrationError::UnknownMigrationFormat(_) => {
write!(f,"Invalid migration directory, the directory's name should be \
<timestamp>_<name_of_migration>, and it should only contain up.sql and down.sql.")
}
MigrationError::UnknownMigrationFormat(_) => write!(
f,
"Invalid migration directory, the directory's name should be \
<timestamp>_<name_of_migration>, and it should only contain up.sql and down.sql."
),
MigrationError::IoError(ref error) => write!(f, "{}", error),
MigrationError::UnknownMigrationVersion(_) => write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion diesel/src/mysql/connection/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ConnectionOptions {
Some(password) => Some(decode_into_cstring(password)?),
None => None,
};
let database = match url.path_segments().and_then(|mut iter| iter.nth(0)) {
let database = match url.path_segments().and_then(|mut iter| iter.next()) {
Some("") | None => None,
Some(segment) => Some(CString::new(segment.as_bytes())?),
};
Expand Down
1 change: 0 additions & 1 deletion diesel_cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::error::Error;
use std::fs;
use std::io::Read;
use std::path::PathBuf;
use toml;

use super::find_project_root;
use print_schema;
Expand Down
2 changes: 1 addition & 1 deletion diesel_cli/src/infer_schema_internals/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn load_foreign_key_constraints(
.collect())
})
.collect::<QueryResult<Vec<Vec<_>>>>()?;
Ok(rows.into_iter().flat_map(|x| x).collect())
Ok(rows.into_iter().flatten().collect())
}

pub fn get_table_data(
Expand Down
5 changes: 2 additions & 3 deletions diesel_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ fn migrations_dir(matches: &ArgMatches) -> Result<PathBuf, MigrationError> {
Config::read(matches)
.unwrap_or_else(handle_error)
.migrations_directory?
.dir
.to_owned(),
.dir,
)
});

Expand Down Expand Up @@ -248,7 +247,7 @@ fn create_migrations_dir(matches: &ArgMatches) -> DatabaseResult<PathBuf> {
create_migrations_directory(&dir)?;
}

Ok(dir.to_owned())
Ok(dir)
}

fn create_config_file(matches: &ArgMatches) -> DatabaseResult<()> {
Expand Down
2 changes: 1 addition & 1 deletion diesel_derives/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl MetaItem {
}

pub fn ident_value(&self) -> Result<syn::Ident, Diagnostic> {
let maybe_attr = self.nested().ok().and_then(|mut n| n.nth(0));
let maybe_attr = self.nested().ok().and_then(|mut n| n.next());
let maybe_path = maybe_attr.as_ref().and_then(|m| m.path().ok());
match maybe_path {
Some(x) => {
Expand Down
8 changes: 7 additions & 1 deletion diesel_derives/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ pub fn wrap_in_dummy_mod(item: TokenStream) -> TokenStream {
quote! {
#[allow(unused_imports)]
const _: () = {
// This import is not actually redundant. When using diesel_derives
// inside of diesel, `diesel` doesn't exist as an extern crate, and
// to work around that it contains a private
// `mod diesel { pub use super::*; }` that this import will then
// refer to. In all other cases, this imports refers to the extern
// crate diesel.
use diesel;

#item
Expand Down Expand Up @@ -46,7 +52,7 @@ fn option_ty_arg(ty: &Type) -> Option<&Type> {
pub fn ty_for_foreign_derive(item: &DeriveInput, flags: &MetaItem) -> Result<Type, Diagnostic> {
if flags.has_flag("foreign_derive") {
match item.data {
Data::Struct(ref body) => match body.fields.iter().nth(0) {
Data::Struct(ref body) => match body.fields.iter().next() {
Some(field) => Ok(field.ty.clone()),
None => Err(flags
.span()
Expand Down
2 changes: 1 addition & 1 deletion diesel_migrations/migrations_internals/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn version_from_path(path: &Path) -> Result<String, MigrationError> {
.unwrap_or_else(|| panic!("Can't get file name from path `{:?}`", path))
.to_string_lossy()
.split('_')
.nth(0)
.next()
.map(|s| Ok(s.replace('-', "")))
.unwrap_or_else(|| Err(MigrationError::UnknownMigrationFormat(path.to_path_buf())))
}
Expand Down