Skip to content

Commit

Permalink
run cargo fmt (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus authored Sep 18, 2017
1 parent 526df30 commit 216ba8a
Show file tree
Hide file tree
Showing 99 changed files with 3,557 additions and 2,640 deletions.
19 changes: 10 additions & 9 deletions benches/elastic/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![feature(plugin)]
#![plugin(json_str)]

#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate elastic_derive;
#[macro_use]
extern crate serde_derive;

extern crate serde;
extern crate elastic;
extern crate serde;

extern crate measure;

Expand Down Expand Up @@ -48,13 +48,14 @@ fn main() {
.params(|p| p.header(http::header::Connection::keep_alive()))
.build()
.unwrap();

let results = measure::run(runs, || {
client.search::<BenchDoc>()
.index("bench_index")
.body(BODY)
.send()
.unwrap()
client
.search::<BenchDoc>()
.index("bench_index")
.body(BODY)
.send()
.unwrap()
});

println!("{}", results);
Expand Down
17 changes: 9 additions & 8 deletions benches/elastic_async/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![feature(plugin)]
#![plugin(json_str)]

#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate elastic_derive;
extern crate futures;
#[macro_use]
extern crate serde_derive;
extern crate tokio_core;

extern crate serde;
extern crate elastic;
extern crate serde;

extern crate measure;

Expand Down Expand Up @@ -50,12 +50,13 @@ fn main() {
.params(|p| p.header(http::header::Connection::keep_alive()))
.build(&core.handle())
.unwrap();

let results_future = measure::run_future(runs, || {
client.search::<BenchDoc>()
.index("bench_index")
.body(BODY)
.send()
client
.search::<BenchDoc>()
.index("bench_index")
.body(BODY)
.send()
});

results = core.run(results_future).unwrap();
Expand Down
43 changes: 22 additions & 21 deletions benches/elastic_bulk/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
//! Elasticsearch Reqwest Client Samples
//!
//! This sample assumes you have a node running on `localhost`.
//!
//!
//! This sample demonstrates a request with a large body.
//!
//! If you compile with `--features profile_memory` then it uses the system allocator
//!
//! If you compile with `--features profile_memory` then it uses the system allocator
//! to play nicely with valgrind for profile_memory.

#![cfg_attr(feature="profile_memory", feature(alloc_system))]
#[cfg(feature="profile_memory")]
#![cfg_attr(feature = "profile_memory", feature(alloc_system))]
#[cfg(feature = "profile_memory")]
extern crate alloc_system;

extern crate elastic;
#[cfg(feature = "inlinable_string")]
extern crate inlinable_string;
#[macro_use]
extern crate lazy_static;
#[cfg(feature="string_cache")]
#[cfg(feature = "string_cache")]
extern crate string_cache;
#[cfg(feature="inlinable_string")]
extern crate inlinable_string;
extern crate elastic;

extern crate reqwest;

Expand All @@ -26,19 +26,19 @@ extern crate measure;
use elastic::http;
use elastic::prelude::*;

#[cfg(not(any(feature="string_cache", feature="inlinable_string")))]
#[cfg(not(any(feature = "string_cache", feature = "inlinable_string")))]
type AllocatedField = String;

#[cfg(feature="string_cache")]
#[cfg(feature = "string_cache")]
type AllocatedField = string_cache::DefaultAtom;

#[cfg(feature="inlinable_string")]
#[cfg(feature = "inlinable_string")]
type AllocatedField = inlinable_string::InlinableString;

#[cfg(not(feature="errors_only"))]
#[cfg(not(feature = "errors_only"))]
type BulkResponseType = elastic::prelude::BulkResponse<AllocatedField, AllocatedField, AllocatedField>;

#[cfg(feature="errors_only")]
#[cfg(feature = "errors_only")]
type BulkResponseType = elastic::prelude::BulkErrorsResponse<AllocatedField, AllocatedField, AllocatedField>;

// Create a bulk request to index a bunch of docs.
Expand Down Expand Up @@ -67,12 +67,12 @@ fn get_req() -> &'static str {
&REQUEST
}

#[cfg(feature="gzip")]
#[cfg(feature = "gzip")]
fn http_client() -> reqwest::Client {
reqwest::Client::new()
}

#[cfg(not(feature="gzip"))]
#[cfg(not(feature = "gzip"))]
fn http_client() -> reqwest::Client {
let mut http = reqwest::Client::new();
http.gzip(false);
Expand All @@ -88,12 +88,13 @@ fn main() {
.params(|p| p.header(http::header::Connection::keep_alive()))
.build()
.unwrap();

let results = measure::run(runs, || {
client.request(BulkRequest::new(get_req()))
.send()
.and_then(|res| res.into_response::<BulkResponseType>())
.unwrap()
client
.request(BulkRequest::new(get_req()))
.send()
.and_then(|res| res.into_response::<BulkResponseType>())
.unwrap()
});

println!("{}", results);
Expand Down
2 changes: 1 addition & 1 deletion benches/elastic_raw/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() {
.params(|p| p.header(http::header::Connection::keep_alive()))
.build()
.unwrap();

let results = measure::run(runs, || {
let req = SearchRequest::for_index_ty("bench_index", "bench_doc", BODY);
let mut res = client.request(req).send().unwrap().into_raw();
Expand Down
28 changes: 11 additions & 17 deletions benches/measure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![feature(test)]

extern crate stopwatch;
extern crate time;
extern crate test;
extern crate time;

use std::env;
use std::fmt;
Expand All @@ -12,7 +12,7 @@ use stopwatch::Stopwatch;
pub struct Measure {
runs: usize,
mean: i64,
percentiles: Vec<(f32, i64)>
percentiles: Vec<(f32, i64)>,
}

impl fmt::Display for Measure {
Expand All @@ -34,17 +34,21 @@ pub fn parse_runs_from_env() -> usize {

// Get the command name
let _ = args.next().unwrap();

// Get the first argument as a usize
if args.len() >= 1 {
args.next().unwrap().parse::<usize>().unwrap_or(default_runs)
args.next()
.unwrap()
.parse::<usize>()
.unwrap_or(default_runs)
} else {
default_runs
}
}

pub fn run<F, FOut>(runs: usize, mut f: F) -> Measure
where F: FnMut() -> FOut
where
F: FnMut() -> FOut,
{
let mut results = Vec::<i64>::with_capacity(runs as usize);
for _ in 0..runs {
Expand All @@ -66,22 +70,12 @@ pub fn run<F, FOut>(runs: usize, mut f: F) -> Measure
Measure {
runs: runs,
mean: mean,
percentiles: pv
percentiles: pv,
}
}

fn percentiles(data: &Vec<i64>, runs: f32) -> Vec<(f32, i64)> {
vec![
0.50,
0.66,
0.75,
0.80,
0.90,
0.95,
0.98,
0.99,
1.00
]
vec![0.50, 0.66, 0.75, 0.80, 0.90, 0.95, 0.98, 0.99, 1.00]
.iter()
.map(|p| {
let p: f32 = *p;
Expand Down
9 changes: 6 additions & 3 deletions benches/prepare/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde;

extern crate elastic;
#[macro_use]
extern crate elastic_derive;
extern crate elastic;

use elastic::prelude::*;

Expand Down Expand Up @@ -33,7 +33,10 @@ fn main() {

client.index_create(index()).send().unwrap();

client.document_put_mapping::<BenchDoc>(index()).send().unwrap();
client
.document_put_mapping::<BenchDoc>(index())
.send()
.unwrap();

for i in 0..10 {
let doc = BenchDoc {
Expand Down
5 changes: 3 additions & 2 deletions benches/rs-es/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ fn main() {

let mut client = Client::new("http://localhost:9200").unwrap();
let qry = Query::build_query_string("*").build();

let results = measure::run(runs, || {
let res: SearchResult<BenchDoc> = client.search_query()
let res: SearchResult<BenchDoc> = client
.search_query()
.with_indexes(&["bench_index"])
.with_types(&["bench_doc"])
.with_query(&qry)
Expand Down
8 changes: 4 additions & 4 deletions examples/account_sample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
//!
//! It expects you have an Elasticsearch node running on `localhost:9200`.

#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate elastic_derive;
#[macro_use]
extern crate quick_error;
#[macro_use]
extern crate serde_derive;

extern crate elastic;
#[macro_use]
extern crate serde_json;
extern crate elastic;

pub mod model;
pub mod ops;
Expand Down Expand Up @@ -40,7 +40,7 @@ fn run() -> Result<(), Box<Error>> {
}

Ok(())
}
}

fn main() {
run().unwrap()
Expand Down
9 changes: 3 additions & 6 deletions examples/account_sample/src/model/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
//! Field serialisation and mapping is all handled in the same place
//! so it's always in sync.

use elastic::types::prelude::{KeywordFieldType, Text, DefaultTextMapping, TextMapping,
Keyword, DefaultKeywordMapping, DocumentType};
use elastic::types::prelude::{DefaultKeywordMapping, DefaultTextMapping, DocumentType, Keyword, KeywordFieldType, Text, TextMapping};

/// Our main model; an account in the bank.
#[derive(Debug, Serialize, Deserialize, ElasticType)]
Expand Down Expand Up @@ -46,10 +45,8 @@ pub type State = Keyword<DefaultKeywordMapping>;

#[derive(Debug, Serialize, Deserialize)]
pub enum Gender {
#[serde(rename = "F")]
Female,
#[serde(rename = "M")]
Male,
#[serde(rename = "F")] Female,
#[serde(rename = "M")] Male,
}

impl KeywordFieldType<DefaultKeywordMapping> for Gender {}
Expand Down
17 changes: 11 additions & 6 deletions examples/account_sample/src/ops/commands/put_bulk_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use std::io::{Result as IoResult, Error as IoError};
use std::io::{Error as IoError, Result as IoResult};
use std::fs::File;
use std::path::Path;
use ops::Client;
use elastic::client::requests::{SyncBody, BulkRequest};
use elastic::client::requests::{BulkRequest, SyncBody};
use elastic::client::responses::bulk::{BulkErrorsResponse, ErrorItem};
use elastic::Error as ResponseError;

use model;

pub trait PutBulkAccounts {
fn put_bulk_accounts<P>(&self, path: P) -> Result<(), PutBulkAccountsError> where P: AsRef<Path>;
fn put_bulk_accounts<P>(&self, path: P) -> Result<(), PutBulkAccountsError>
where
P: AsRef<Path>;
}

impl PutBulkAccounts for Client {
fn put_bulk_accounts<P>(&self, path: P) -> Result<(), PutBulkAccountsError>
where P: AsRef<Path>
where
P: AsRef<Path>,
{
let body = bulk_body(path)?;
let req = put(body);
Expand All @@ -34,13 +37,15 @@ impl PutBulkAccounts for Client {
}

fn put<B>(body: B) -> BulkRequest<'static, B>
where B: Into<SyncBody>
where
B: Into<SyncBody>,
{
BulkRequest::for_index_ty(model::index::name(), model::account::name(), body)
}

fn bulk_body<P>(path: P) -> IoResult<File>
where P: AsRef<Path>
where
P: AsRef<Path>,
{
File::open(path)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/async_raw_sample/src/body/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod request;
pub mod response;
pub mod response;
Loading

0 comments on commit 216ba8a

Please sign in to comment.