From e1e12df194f80151a71f7323391002dc631450e2 Mon Sep 17 00:00:00 2001 From: Stefan Ruzitschka Date: Tue, 8 Oct 2019 13:10:41 +0200 Subject: [PATCH] [bump] rust to 1.38.0 --- src/elasticsearch.rs | 11 ++++++----- src/elasticsearch_test.rs | 9 ++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/elasticsearch.rs b/src/elasticsearch.rs index 150cbfc..17bff86 100644 --- a/src/elasticsearch.rs +++ b/src/elasticsearch.rs @@ -11,6 +11,7 @@ use serde_json::json; use serde_json::to_writer; use std::collections::HashMap; use std::fmt; +use std::fmt::{Display, Formatter}; use std::io::Write; #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] @@ -21,12 +22,12 @@ pub enum Value { String(String), } -impl Value { - pub fn to_string(&self) -> String { +impl Display for Value { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - Value::Bool(b) => format!("{}", b), - Value::Int(i) => format!("{}", i), - Value::String(str) => str.clone(), + Value::Bool(b) => write!(f, "{}", b), + Value::Int(i) => write!(f, "{}", i), + Value::String(str) => write!(f, "{}", str), } } } diff --git a/src/elasticsearch_test.rs b/src/elasticsearch_test.rs index ccdd7fc..94d2462 100644 --- a/src/elasticsearch_test.rs +++ b/src/elasticsearch_test.rs @@ -1,4 +1,4 @@ -use super::elasticsearch::{ElasticsearchUrlBuilder, Query, QueryRequest, SortOrder}; +use super::elasticsearch::{ElasticsearchUrlBuilder, Query, QueryRequest, SortOrder, Value}; use serde_json; use spectral::prelude::*; @@ -102,3 +102,10 @@ fn test_build_url_delete_by_query() { assert_that(&url_builder.delete_by_query()).is_equal_to("http://server/INDEX_NAME/_delete_by_query".to_string()); } + +#[test] +fn test_value_display() { + assert_eq!(format!("{}", Value::Bool(true)), "true"); + assert_eq!(format!("{}", Value::Int(1)), "1"); + assert_eq!(format!("{}", Value::String("lol".to_owned())), "lol"); +}