From 1205d6e91ebd2eed29362d4a0c8dd17b2ae01827 Mon Sep 17 00:00:00 2001 From: Koxiaet <38139193+Koxiaet@users.noreply.github.com> Date: Fri, 16 Oct 2020 06:37:48 +0100 Subject: [PATCH] Remove itertools dependency --- Cargo.toml | 1 - derive/Cargo.toml | 1 - examples | 2 +- src/registry/export_sdl.rs | 39 ++++++++++++++++-------------------- src/schema.rs | 3 +-- src/validation/suggestion.rs | 29 +++++++++++++++++---------- 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96a87a15..c461a5c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,6 @@ async-trait = "0.1.41" fnv = "1.0.6" futures = "0.3.6" indexmap = "1.6.0" -itertools = "0.9.0" once_cell = "1.3.1" pin-project-lite = "0.1.10" regex = "1.4.1" diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 0d84e6fc..89c5e2d4 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -22,6 +22,5 @@ syn = { version = "1.0.44", features = ["full", "extra-traits", "visit-mut"] } quote = "1.0.3" Inflector = "0.11.4" proc-macro-crate = "0.1.4" -itertools = "0.9.0" darling = "0.10" thiserror = "1.0" diff --git a/examples b/examples index f085046e..cb336084 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit f085046edb8933754ddc71c5da577d7b44bcf0bb +Subproject commit cb3360847366d2fd70a33eb5f9df60e90e8979da diff --git a/src/registry/export_sdl.rs b/src/registry/export_sdl.rs index 73e9e8e3..e40cdb07 100644 --- a/src/registry/export_sdl.rs +++ b/src/registry/export_sdl.rs @@ -1,7 +1,5 @@ use std::fmt::Write; -use itertools::Itertools; - use crate::registry::{MetaField, MetaInputValue, MetaType, Registry}; impl Registry { @@ -59,18 +57,14 @@ impl Registry { .ok(); } if !field.args.is_empty() { - write!( - sdl, - "\t{}({}): {}", - field.name, - field - .args - .values() - .map(|arg| export_input_value(arg)) - .join(", "), - field.ty - ) - .ok(); + write!(sdl, "\t{}(", field.name).ok(); + for (i, arg) in field.args.values().enumerate() { + if i != 0 { + sdl.push_str(", "); + } + sdl.push_str(&export_input_value(arg)); + } + write!(sdl, "): {}", field.ty).ok(); } else { write!(sdl, "\t{}: {}", field.name, field.ty).ok(); } @@ -137,7 +131,10 @@ impl Registry { write!(sdl, "type {} ", name).ok(); if let Some(implements) = self.implements.get(name) { if !implements.is_empty() { - write!(sdl, "implements {} ", implements.iter().join(" & ")).ok(); + write!(sdl, "implements ").ok(); + for interface in implements { + write!(sdl, "& {} ", interface).ok(); + } } } @@ -223,13 +220,11 @@ impl Registry { if description.is_some() && !federation { writeln!(sdl, "\"\"\"\n{}\n\"\"\"", description.unwrap()).ok(); } - writeln!( - sdl, - "union {} = {}", - name, - possible_types.iter().join(" | ") - ) - .ok(); + write!(sdl, "union {} =", name).ok(); + for ty in possible_types { + write!(sdl, " | {}", ty).ok(); + } + writeln!(sdl).ok(); } } } diff --git a/src/schema.rs b/src/schema.rs index 519732f5..6b2f32bd 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -6,7 +6,6 @@ use std::sync::Arc; use futures::stream::{self, Stream, StreamExt}; use indexmap::map::IndexMap; -use itertools::Itertools; use crate::context::{Data, QueryEnvInner, ResolveId}; use crate::extensions::{ErrorLogger, ExtensionContext, ExtensionFactory, Extensions}; @@ -339,7 +338,7 @@ where .extensions .iter() .map(|factory| factory.create()) - .collect_vec() + .collect::>() .into(); let request = extensions diff --git a/src/validation/suggestion.rs b/src/validation/suggestion.rs index 66512650..2b661512 100644 --- a/src/validation/suggestion.rs +++ b/src/validation/suggestion.rs @@ -1,9 +1,8 @@ use std::collections::HashMap; - -use itertools::Itertools; +use std::fmt::Write; fn levenshtein_distance(s1: &str, s2: &str) -> usize { - let mut column = (0..=s1.len()).collect_vec(); + let mut column: Vec<_> = (0..=s1.len()).collect(); for (x, rx) in s2.bytes().enumerate() { column[0] = x + 1; let mut lastdiag = x; @@ -40,12 +39,20 @@ where } selected.sort_by(|a, b| distances[a].cmp(&distances[b])); - Some(format!( - "{} {}?", - prefix, - selected - .into_iter() - .map(|s| format!("\"{}\"", s)) - .join(", ") - )) + let mut suggestion = String::with_capacity( + prefix.len() + selected.iter().map(|s| s.len() + 5).sum::() + ); + suggestion.push_str(prefix); + suggestion.push(' '); + + for (i, s) in selected.iter().enumerate() { + if i != 0 { + suggestion.push_str(" , "); + } + write!(suggestion, "\"{}\"", s).unwrap(); + } + + suggestion.push('?'); + + Some(suggestion) }