Merge pull request #184 from Orange-OpenSource/feature/update-rust-1.51

Fix new clippy warnings (Rust 1.51)
This commit is contained in:
Fabrice Reix 2021-03-28 18:44:18 +02:00 committed by GitHub
commit 8f4b594e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 119 additions and 129 deletions

View File

@ -16,7 +16,7 @@
*
*/
use crate::cli::CLIError;
use crate::cli::CliError;
use std::fs;
use std::fs::File;
use std::io::prelude::*;
@ -30,11 +30,11 @@ fn strip_bom(bytes: &mut Vec<u8>) {
/// Similar to the standard read_to_string()
/// But remove any existing BOM
pub fn read_to_string(filename: &str) -> Result<String, CLIError> {
pub fn read_to_string(filename: &str) -> Result<String, CliError> {
let mut f = match File::open(&filename) {
Ok(f) => f,
Err(e) => {
return Err(CLIError {
return Err(CliError {
message: e.to_string(),
})
}
@ -42,19 +42,19 @@ pub fn read_to_string(filename: &str) -> Result<String, CLIError> {
let metadata = fs::metadata(&filename).expect("unable to read metadata");
let mut buffer = vec![0; metadata.len() as usize];
if let Err(e) = f.read(&mut buffer) {
return Err(CLIError {
return Err(CliError {
message: e.to_string(),
});
}
string_from_utf8(buffer)
}
pub fn string_from_utf8(buffer: Vec<u8>) -> Result<String, CLIError> {
pub fn string_from_utf8(buffer: Vec<u8>) -> Result<String, CliError> {
let mut buffer = buffer;
strip_bom(&mut buffer);
match String::from_utf8(buffer) {
Ok(s) => Ok(s),
Err(e) => Err(CLIError {
Err(e) => Err(CliError {
message: e.to_string(),
}),
}
@ -94,7 +94,7 @@ pub mod tests {
);
assert_eq!(
string_from_utf8(vec![0xef]).err().unwrap(),
CLIError {
CliError {
message: "incomplete utf-8 byte sequence from index 0".to_string()
}
);

View File

@ -29,6 +29,6 @@ mod logger;
mod variables;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CLIError {
pub struct CliError {
pub message: String,
}

View File

@ -16,12 +16,12 @@
*
*/
use crate::cli::CLIError;
use crate::cli::CliError;
use crate::runner::Value;
pub fn parse(s: &str) -> Result<(String, Value), CLIError> {
pub fn parse(s: &str) -> Result<(String, Value), CliError> {
match s.find('=') {
None => Err(CLIError {
None => Err(CliError {
message: format!("Missing value for variable {}!", s),
}),
Some(index) => {
@ -32,7 +32,7 @@ pub fn parse(s: &str) -> Result<(String, Value), CLIError> {
}
}
fn parse_value(s: &str) -> Result<Value, CLIError> {
fn parse_value(s: &str) -> Result<Value, CliError> {
if s == "true" {
Ok(Value::Bool(true))
} else if s == "false" {
@ -50,7 +50,7 @@ fn parse_value(s: &str) -> Result<Value, CLIError> {
if let Some(s) = s.strip_suffix('"') {
Ok(Value::String(s.to_string()))
} else {
Err(CLIError {
Err(CliError {
message: "Value should end with a double quote".to_string(),
})
}
@ -98,7 +98,7 @@ pub mod tests {
fn test_parse_error() {
assert_eq!(
parse("name").err().unwrap(),
CLIError {
CliError {
message: "Missing value for variable name!".to_string()
}
);
@ -129,7 +129,7 @@ pub mod tests {
fn test_parse_value_error() {
assert_eq!(
parse_value("\"123").err().unwrap(),
CLIError {
CliError {
message: "Value should end with a double quote".to_string()
}
)

View File

@ -36,7 +36,7 @@ pub enum HttpError {
FailToConnect,
TooManyRedirect,
CouldNotParseResponse,
SSLCertificate(Option<String>),
SslCertificate(Option<String>),
InvalidUrl,
Timeout,
StatuslineIsMissing,
@ -208,7 +208,7 @@ impl Client {
6 => Err(HttpError::CouldNotResolveHost),
7 => Err(HttpError::FailToConnect),
28 => Err(HttpError::Timeout),
60 => Err(HttpError::SSLCertificate(
60 => Err(HttpError::SslCertificate(
e.extra_description().map(String::from),
)),
_ => Err(HttpError::Other {

View File

@ -29,7 +29,7 @@ use clap::{AppSettings, ArgMatches};
use hurl::cli;
use hurl::cli::interactive;
use hurl::cli::CLIError;
use hurl::cli::CliError;
use hurl::html;
use hurl::http;
use hurl::runner;
@ -40,7 +40,7 @@ use hurl_core::parser;
use std::fs::File;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CLIOptions {
pub struct CliOptions {
pub verbose: bool,
pub color: bool,
pub fail_fast: bool,
@ -75,7 +75,7 @@ fn execute(
contents: String,
current_dir: &Path,
file_root: Option<String>,
cli_options: CLIOptions,
cli_options: CliOptions,
log_verbose: &impl Fn(&str),
log_error_message: &impl Fn(bool, &str),
) -> HurlResult {
@ -218,11 +218,11 @@ fn output_color(matches: ArgMatches) -> bool {
}
}
fn to_entry(matches: ArgMatches) -> Result<Option<usize>, CLIError> {
fn to_entry(matches: ArgMatches) -> Result<Option<usize>, CliError> {
match matches.value_of("to_entry") {
Some(value) => match value.parse() {
Ok(v) => Ok(Some(v)),
Err(_) => Err(CLIError {
Err(_) => Err(CliError {
message: "Invalid value for option --to-entry - must be a positive integer!"
.to_string(),
}),
@ -234,7 +234,7 @@ fn to_entry(matches: ArgMatches) -> Result<Option<usize>, CLIError> {
fn json_file(
matches: ArgMatches,
log_verbose: impl Fn(&str),
) -> Result<(Vec<HurlResult>, Option<std::path::PathBuf>), CLIError> {
) -> Result<(Vec<HurlResult>, Option<std::path::PathBuf>), CliError> {
if let Some(filename) = matches.value_of("json") {
let path = Path::new(filename);
@ -245,7 +245,7 @@ fn json_file(
let v: serde_json::Value = match serde_json::from_str(data.as_str()) {
Ok(val) => val,
Err(_) => {
return Err(CLIError {
return Err(CliError {
message: format!("The file {} is not a valid json file", path.display()),
});
}
@ -253,7 +253,7 @@ fn json_file(
match runner::deserialize_results(v) {
Err(msg) => {
return Err(CLIError {
return Err(CliError {
message: format!("Existing Hurl json can not be parsed! - {}", msg),
});
}
@ -269,14 +269,14 @@ fn json_file(
}
}
fn html_report(matches: ArgMatches) -> Result<Option<std::path::PathBuf>, CLIError> {
fn html_report(matches: ArgMatches) -> Result<Option<std::path::PathBuf>, CliError> {
if let Some(dir) = matches.value_of("html_report") {
let path = Path::new(dir);
if std::path::Path::new(&path).exists() {
Ok(Some(path.to_path_buf()))
} else {
match std::fs::create_dir(path) {
Err(_) => Err(CLIError {
Err(_) => Err(CliError {
message: format!("Html dir {} can not be created", path.display()),
}),
Ok(_) => Ok(Some(path.to_path_buf())),
@ -287,13 +287,13 @@ fn html_report(matches: ArgMatches) -> Result<Option<std::path::PathBuf>, CLIErr
}
}
fn variables(matches: ArgMatches) -> Result<HashMap<String, Value>, CLIError> {
fn variables(matches: ArgMatches) -> Result<HashMap<String, Value>, CliError> {
let mut variables = HashMap::new();
if let Some(filename) = matches.value_of("variables_file") {
let path = std::path::Path::new(filename);
if !path.exists() {
return Err(CLIError {
return Err(CliError {
message: format!("Properties file {} does not exist", path.display()),
});
}
@ -304,7 +304,7 @@ fn variables(matches: ArgMatches) -> Result<HashMap<String, Value>, CLIError> {
let line = match line {
Ok(s) => s,
Err(_) => {
return Err(CLIError {
return Err(CliError {
message: format!("Can not parse line {} of {}", index + 1, path.display()),
})
}
@ -513,7 +513,7 @@ fn app() -> clap::App<'static, 'static> {
pub fn unwrap_or_exit<T>(
log_error_message: &impl Fn(bool, &str),
result: Result<T, CLIError>,
result: Result<T, CliError>,
) -> T {
match result {
Ok(v) => v,
@ -524,7 +524,7 @@ pub fn unwrap_or_exit<T>(
}
}
fn parse_options(matches: ArgMatches) -> Result<CLIOptions, CLIError> {
fn parse_options(matches: ArgMatches) -> Result<CliOptions, CliError> {
let verbose = matches.is_present("verbose") || matches.is_present("interactive");
let color = output_color(matches.clone());
let fail_fast = !matches.is_present("fail_at_end");
@ -543,7 +543,7 @@ fn parse_options(matches: ArgMatches) -> Result<CLIOptions, CLIError> {
Some(s) => match s.parse::<usize>() {
Ok(x) => Some(x),
Err(_) => {
return Err(CLIError {
return Err(CliError {
message: "max_redirs option can not be parsed".to_string(),
});
}
@ -555,7 +555,7 @@ fn parse_options(matches: ArgMatches) -> Result<CLIOptions, CLIError> {
Some(s) => match s.parse::<u64>() {
Ok(n) => Duration::from_secs(n),
Err(_) => {
return Err(CLIError {
return Err(CliError {
message: "max_time option can not be parsed".to_string(),
});
}
@ -567,7 +567,7 @@ fn parse_options(matches: ArgMatches) -> Result<CLIOptions, CLIError> {
Some(s) => match s.parse::<u64>() {
Ok(n) => Duration::from_secs(n),
Err(_) => {
return Err(CLIError {
return Err(CliError {
message: "connect-timeout option can not be parsed".to_string(),
});
}
@ -576,7 +576,7 @@ fn parse_options(matches: ArgMatches) -> Result<CLIOptions, CLIError> {
let compressed = matches.is_present("compressed");
let user = matches.value_of("user").map(|x| x.to_string());
let interactive = matches.is_present("interactive");
Ok(CLIOptions {
Ok(CliOptions {
verbose,
color,
fail_fast,
@ -810,7 +810,7 @@ fn exit_code(hurl_results: Vec<HurlResult>) -> i32 {
}
}
fn write_output(bytes: Vec<u8>, filename: Option<&str>) -> Result<(), CLIError> {
fn write_output(bytes: Vec<u8>, filename: Option<&str>) -> Result<(), CliError> {
match filename {
None => {
let stdout = io::stdout();
@ -825,7 +825,7 @@ fn write_output(bytes: Vec<u8>, filename: Option<&str>) -> Result<(), CLIError>
let path = Path::new(filename);
let mut file = match std::fs::File::create(&path) {
Err(why) => {
return Err(CLIError {
return Err(CliError {
message: format!("Issue writing to {}: {:?}", path.display(), why),
});
}
@ -838,9 +838,9 @@ fn write_output(bytes: Vec<u8>, filename: Option<&str>) -> Result<(), CLIError>
}
}
pub fn cookies_output_file(filename: String, n: usize) -> Result<std::path::PathBuf, CLIError> {
pub fn cookies_output_file(filename: String, n: usize) -> Result<std::path::PathBuf, CliError> {
if n > 1 {
Err(CLIError {
Err(CliError {
message: "Only save cookies for a unique session".to_string(),
})
} else {
@ -849,10 +849,10 @@ pub fn cookies_output_file(filename: String, n: usize) -> Result<std::path::Path
}
}
fn write_cookies_file(file_path: PathBuf, hurl_results: Vec<HurlResult>) -> Result<(), CLIError> {
fn write_cookies_file(file_path: PathBuf, hurl_results: Vec<HurlResult>) -> Result<(), CliError> {
let mut file = match std::fs::File::create(&file_path) {
Err(why) => {
return Err(CLIError {
return Err(CliError {
message: format!("Issue writing to {}: {:?}", file_path.display(), why),
});
}
@ -865,7 +865,7 @@ fn write_cookies_file(file_path: PathBuf, hurl_results: Vec<HurlResult>) -> Resu
.to_string();
match hurl_results.first() {
None => {
return Err(CLIError {
return Err(CliError {
message: "Issue fetching results".to_string(),
});
}
@ -878,14 +878,14 @@ fn write_cookies_file(file_path: PathBuf, hurl_results: Vec<HurlResult>) -> Resu
}
if let Err(why) = file.write_all(s.as_bytes()) {
return Err(CLIError {
return Err(CliError {
message: format!("Issue writing to {}: {:?}", file_path.display(), why),
});
}
Ok(())
}
fn write_html_report(dir_path: PathBuf, hurl_results: Vec<HurlResult>) -> Result<(), CLIError> {
fn write_html_report(dir_path: PathBuf, hurl_results: Vec<HurlResult>) -> Result<(), CliError> {
//let now: DateTime<Utc> = Utc::now();
let now: DateTime<Local> = Local::now();
let html = create_html_index(now.to_rfc2822(), hurl_results);
@ -894,14 +894,14 @@ fn write_html_report(dir_path: PathBuf, hurl_results: Vec<HurlResult>) -> Result
let file_path = dir_path.join("index.html");
let mut file = match std::fs::File::create(&file_path) {
Err(why) => {
return Err(CLIError {
return Err(CliError {
message: format!("Issue writing to {}: {:?}", file_path.display(), why),
});
}
Ok(file) => file,
};
if let Err(why) = file.write_all(s.as_bytes()) {
return Err(CLIError {
return Err(CliError {
message: format!("Issue writing to {}: {:?}", file_path.display(), why),
});
}
@ -909,14 +909,14 @@ fn write_html_report(dir_path: PathBuf, hurl_results: Vec<HurlResult>) -> Result
let file_path = dir_path.join("report.css");
let mut file = match std::fs::File::create(&file_path) {
Err(why) => {
return Err(CLIError {
return Err(CliError {
message: format!("Issue writing to {}: {:?}", file_path.display(), why),
});
}
Ok(file) => file,
};
if let Err(why) = file.write_all(include_bytes!("report.css")) {
return Err(CLIError {
return Err(CliError {
message: format!("Issue writing to {}: {:?}", file_path.display(), why),
});
}

View File

@ -48,9 +48,9 @@ impl Encoding {
pub fn decode(&self, data: &[u8]) -> Result<Vec<u8>, RunnerError> {
match self {
Encoding::Identity => Ok(data.to_vec()),
Encoding::Gzip => uncompress_gzip(&data[..]),
Encoding::Deflate => uncompress_zlib(&data[..]),
Encoding::Brotli => uncompress_brotli(&data[..]),
Encoding::Gzip => uncompress_gzip(data),
Encoding::Deflate => uncompress_zlib(data),
Encoding::Brotli => uncompress_brotli(data),
}
}
}

View File

@ -121,7 +121,7 @@ pub enum RunnerError {
InvalidJson {
value: String,
},
InvalidURL(String),
InvalidUrl(String),
HttpConnection {
url: String,
@ -133,7 +133,7 @@ pub enum RunnerError {
Timeout,
TooManyRedirect,
CouldNotParseResponse,
SSLCertificate(String),
SslCertificate(String),
UnsupportedContentEncoding(String),
CouldNotUncompressResponse(String),

View File

@ -109,10 +109,10 @@ pub fn run(
HttpError::Timeout => RunnerError::Timeout,
HttpError::TooManyRedirect => RunnerError::TooManyRedirect,
HttpError::CouldNotParseResponse => RunnerError::CouldNotParseResponse,
HttpError::SSLCertificate(description) => RunnerError::SSLCertificate(
HttpError::SslCertificate(description) => RunnerError::SslCertificate(
description.unwrap_or_else(|| "SSL certificate problem".to_string()),
),
HttpError::InvalidUrl => RunnerError::InvalidURL(http_request.url.clone()),
HttpError::InvalidUrl => RunnerError::InvalidUrl(http_request.url.clone()),
HttpError::StatuslineIsMissing => RunnerError::HttpConnection {
message: "status line is missing".to_string(),
url: http_request.url.clone(),

View File

@ -15,7 +15,7 @@ impl Error for runner::Error {
fn description(&self) -> String {
match &self.inner {
RunnerError::InvalidURL(..) => "Invalid url".to_string(),
RunnerError::InvalidUrl(..) => "Invalid url".to_string(),
RunnerError::TemplateVariableNotDefined { .. } => "Undefined Variable".to_string(),
RunnerError::VariableNotDefined { .. } => "Undefined Variable".to_string(),
RunnerError::HttpConnection { .. } => "Http Connection".to_string(),
@ -25,7 +25,7 @@ impl Error for runner::Error {
RunnerError::Timeout => "Http Connection".to_string(),
RunnerError::TooManyRedirect => "Http Connection".to_string(),
RunnerError::CouldNotParseResponse => "Http Connection".to_string(),
RunnerError::SSLCertificate { .. } => "SSL Certificate".to_string(),
RunnerError::SslCertificate { .. } => "SSL Certificate".to_string(),
RunnerError::PredicateValue { .. } => "Assert - Predicate Value Failed".to_string(),
RunnerError::InvalidRegex {} => "Invalid regex".to_string(),
RunnerError::FileReadAccess { .. } => "File ReadAccess".to_string(),
@ -54,7 +54,7 @@ impl Error for runner::Error {
fn fixme(&self) -> String {
match &self.inner {
RunnerError::InvalidURL(url) => format!("Invalid url <{}>", url),
RunnerError::InvalidUrl(url) => format!("Invalid url <{}>", url),
RunnerError::TemplateVariableNotDefined { name } => {
format!("You must set the variable {}", name)
}
@ -67,7 +67,7 @@ impl Error for runner::Error {
RunnerError::Timeout => "Timeout has been reached".to_string(),
RunnerError::TooManyRedirect => "Too many redirect".to_string(),
RunnerError::CouldNotParseResponse => "Could not parse response".to_string(),
RunnerError::SSLCertificate(description) => description.clone(),
RunnerError::SslCertificate(description) => description.clone(),
RunnerError::AssertVersion { actual, .. } => format!("actual value is <{}>", actual),
RunnerError::AssertStatus { actual, .. } => format!("actual value is <{}>", actual),
RunnerError::PredicateValue(value) => {

View File

@ -99,7 +99,7 @@ pub fn eval_query(
};
match result {
Ok(value) => Ok(Some(value)),
Err(xpath::XpathError::InvalidXML {}) => Err(Error {
Err(xpath::XpathError::InvalidXml {}) => Err(Error {
source_info: query.source_info,
inner: RunnerError::QueryInvalidXml,
assert: false,

View File

@ -25,7 +25,7 @@ use super::value::Value;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum XpathError {
InvalidXML,
InvalidXml,
InvalidHtml,
Eval,
Unsupported,
@ -36,12 +36,12 @@ pub fn eval_xml(xml: String, expr: String) -> Result<Value, XpathError> {
match parser.parse_string(xml) {
Ok(doc) => {
if doc.get_root_element() == None {
Err(XpathError::InvalidXML {})
Err(XpathError::InvalidXml {})
} else {
eval(doc, expr)
}
}
Err(_) => Err(XpathError::InvalidXML {}),
Err(_) => Err(XpathError::InvalidXml {}),
}
}
@ -151,7 +151,7 @@ mod tests {
eval_xml(String::from("??"), String::from("//person"))
.err()
.unwrap(),
XpathError::InvalidXML
XpathError::InvalidXml
);
}

View File

@ -542,7 +542,7 @@ fn test_error_ssl() {
} else {
"SSL certificate problem: self signed certificate".to_string()
};
assert_eq!(error, HttpError::SSLCertificate(Some(message)));
assert_eq!(error, HttpError::SslCertificate(Some(message)));
}
#[test]

View File

@ -34,7 +34,7 @@ pub fn templatize(encoded_string: EncodedString) -> ParseResult<'static, Vec<Tem
Template {},
FirstOpenBracket {},
FirstCloseBracket {},
};
}
let mut elements = vec![];

View File

@ -16,7 +16,7 @@
*
*/
use crate::cli::CLIError;
use crate::cli::CliError;
use std::fs;
use std::fs::File;
use std::io::prelude::*;
@ -30,11 +30,11 @@ fn strip_bom(bytes: &mut Vec<u8>) {
/// Similar to the standard read_to_string()
/// But remove any existing BOM
pub fn read_to_string(filename: &str) -> Result<String, CLIError> {
pub fn read_to_string(filename: &str) -> Result<String, CliError> {
let mut f = match File::open(&filename) {
Ok(f) => f,
Err(e) => {
return Err(CLIError {
return Err(CliError {
message: e.to_string(),
})
}
@ -42,19 +42,19 @@ pub fn read_to_string(filename: &str) -> Result<String, CLIError> {
let metadata = fs::metadata(&filename).expect("unable to read metadata");
let mut buffer = vec![0; metadata.len() as usize];
if let Err(e) = f.read(&mut buffer) {
return Err(CLIError {
return Err(CliError {
message: e.to_string(),
});
}
string_from_utf8(buffer)
}
pub fn string_from_utf8(buffer: Vec<u8>) -> Result<String, CLIError> {
pub fn string_from_utf8(buffer: Vec<u8>) -> Result<String, CliError> {
let mut buffer = buffer;
strip_bom(&mut buffer);
match String::from_utf8(buffer) {
Ok(s) => Ok(s),
Err(e) => Err(CLIError {
Err(e) => Err(CliError {
message: e.to_string(),
}),
}
@ -94,7 +94,7 @@ pub mod tests {
);
assert_eq!(
string_from_utf8(vec![0xef]).err().unwrap(),
CLIError {
CliError {
message: "incomplete utf-8 byte sequence from index 0".to_string()
}
);

View File

@ -26,6 +26,6 @@ mod fs;
mod logger;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CLIError {
pub struct CliError {
pub message: String,
}

View File

@ -38,8 +38,7 @@ impl ToJson for HurlFile {
impl ToJson for Entry {
fn to_json(&self) -> JValue {
let mut attributes = vec![];
attributes.push(("request".to_string(), self.request.to_json()));
let mut attributes = vec![("request".to_string(), self.request.to_json())];
if let Some(response) = self.response.clone() {
attributes.push(("response".to_string(), response.to_json()));
}
@ -49,12 +48,13 @@ impl ToJson for Entry {
impl ToJson for Request {
fn to_json(&self) -> JValue {
let mut attributes = vec![];
attributes.push((
"method".to_string(),
JValue::String(self.method.to_string()),
));
attributes.push(("url".to_string(), JValue::String(self.url.to_string())));
let mut attributes = vec![
(
"method".to_string(),
JValue::String(self.method.to_string()),
),
("url".to_string(), JValue::String(self.url.to_string())),
];
add_headers(&mut attributes, self.headers.clone());
if !self.clone().querystring_params().is_empty() {
@ -181,9 +181,10 @@ fn get_json_version(version_value: VersionValue) -> Option<String> {
impl ToJson for KeyValue {
fn to_json(&self) -> JValue {
let mut attributes = vec![];
attributes.push(("name".to_string(), JValue::String(self.key.value.clone())));
attributes.push(("value".to_string(), JValue::String(self.value.to_string())));
let attributes = vec![
("name".to_string(), JValue::String(self.key.value.clone())),
("value".to_string(), JValue::String(self.value.to_string())),
];
JValue::Object(attributes)
}
}
@ -199,12 +200,13 @@ impl ToJson for MultipartParam {
impl ToJson for FileParam {
fn to_json(&self) -> JValue {
let mut attributes = vec![];
attributes.push(("name".to_string(), JValue::String(self.key.value.clone())));
attributes.push((
"filename".to_string(),
JValue::String(self.value.filename.value.clone()),
));
let mut attributes = vec![
("name".to_string(), JValue::String(self.key.value.clone())),
(
"filename".to_string(),
JValue::String(self.value.filename.value.clone()),
),
];
if let Some(content_type) = self.value.content_type.clone() {
attributes.push(("content_type".to_string(), JValue::String(content_type)));
}
@ -214,21 +216,23 @@ impl ToJson for FileParam {
impl ToJson for Cookie {
fn to_json(&self) -> JValue {
let mut attributes = vec![];
attributes.push(("name".to_string(), JValue::String(self.name.value.clone())));
attributes.push((
"value".to_string(),
JValue::String(self.value.value.clone()),
));
let attributes = vec![
("name".to_string(), JValue::String(self.name.value.clone())),
(
"value".to_string(),
JValue::String(self.value.value.clone()),
),
];
JValue::Object(attributes)
}
}
impl ToJson for Capture {
fn to_json(&self) -> JValue {
let mut attributes = vec![];
attributes.push(("name".to_string(), JValue::String(self.name.value.clone())));
attributes.push(("query".to_string(), self.query.to_json()));
let mut attributes = vec![
("name".to_string(), JValue::String(self.name.value.clone())),
("query".to_string(), self.query.to_json()),
];
if let Some(subquery) = self.subquery.clone() {
attributes.push(("subquery".to_string(), subquery.to_json()));
}
@ -238,17 +242,16 @@ impl ToJson for Capture {
impl ToJson for Assert {
fn to_json(&self) -> JValue {
let mut attributes = vec![];
attributes.push(("query".to_string(), self.query.to_json()));
attributes.push(("predicate".to_string(), self.predicate.to_json()));
let attributes = vec![
("query".to_string(), self.query.to_json()),
("predicate".to_string(), self.predicate.to_json()),
];
JValue::Object(attributes)
}
}
impl ToJson for Query {
fn to_json(&self) -> JValue {
let mut attributes = vec![];
attributes.push(("type".to_string(), self.value.to_json()));
self.value.to_json()
}
}

View File

@ -154,8 +154,7 @@ impl Tokenizable for Status {
impl Tokenizable for Version {
fn tokenize(&self) -> Vec<Token> {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::Version(format!(
vec![Token::Version(format!(
"HTTP/{}",
match self.value {
VersionValue::Version1 => String::from("1.0"),
@ -163,8 +162,7 @@ impl Tokenizable for Version {
VersionValue::Version2 => String::from("2"),
VersionValue::VersionAny => String::from("*"),
}
)));
tokens
))]
}
}
@ -340,8 +338,7 @@ impl Tokenizable for FileParam {
impl Tokenizable for FileValue {
fn tokenize(&self) -> Vec<Token> {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::Keyword("file,".to_string()));
let mut tokens: Vec<Token> = vec![Token::Keyword("file,".to_string())];
tokens.append(&mut self.space0.tokenize());
tokens.append(&mut self.filename.tokenize());
tokens.append(&mut self.space1.tokenize());
@ -377,9 +374,7 @@ impl Tokenizable for Cookie {
impl Tokenizable for CookieValue {
fn tokenize(&self) -> Vec<Token> {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::Value(self.clone().value));
tokens
vec![Token::Value(self.clone().value)]
}
}
@ -486,8 +481,7 @@ impl Tokenizable for CookiePath {
impl Tokenizable for CookieAttribute {
fn tokenize(&self) -> Vec<Token> {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::CodeDelimiter("[".to_string()));
let mut tokens: Vec<Token> = vec![Token::CodeDelimiter("[".to_string())];
add_tokens(&mut tokens, self.space0.tokenize());
tokens.push(Token::String(self.name.value()));
add_tokens(&mut tokens, self.space1.tokenize());
@ -720,9 +714,7 @@ impl Tokenizable for TemplateElement {
fn tokenize(&self) -> Vec<Token> {
match self {
TemplateElement::String { encoded, .. } => {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::String(encoded.to_string()));
tokens
vec![Token::String(encoded.to_string())]
}
TemplateElement::Expression(value) => {
let mut tokens: Vec<Token> = vec![];
@ -735,8 +727,7 @@ impl Tokenizable for TemplateElement {
impl Tokenizable for Expr {
fn tokenize(&self) -> Vec<Token> {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::CodeDelimiter(String::from("{{")));
let mut tokens: Vec<Token> = vec![Token::CodeDelimiter(String::from("{{"))];
add_tokens(&mut tokens, self.space0.tokenize());
tokens.push(Token::CodeVariable(self.variable.name.clone()));
add_tokens(&mut tokens, self.space1.tokenize());
@ -769,9 +760,7 @@ impl Tokenizable for Whitespace {
impl Tokenizable for Comment {
fn tokenize(&self) -> Vec<Token> {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::Comment(format!("#{}", self.clone().value)));
tokens
vec![Token::Comment(format!("#{}", self.clone().value))]
}
}
@ -831,8 +820,7 @@ impl Tokenizable for JsonValue {
impl Tokenizable for JsonListElement {
fn tokenize(&self) -> Vec<Token> {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::Whitespace(self.space0.clone()));
let mut tokens: Vec<Token> = vec![Token::Whitespace(self.space0.clone())];
tokens.append(&mut self.value.tokenize());
tokens.push(Token::Whitespace(self.space1.clone()));
tokens
@ -841,8 +829,7 @@ impl Tokenizable for JsonListElement {
impl Tokenizable for JsonObjectElement {
fn tokenize(&self) -> Vec<Token> {
let mut tokens: Vec<Token> = vec![];
tokens.push(Token::Whitespace(self.space0.clone()));
let mut tokens: Vec<Token> = vec![Token::Whitespace(self.space0.clone())];
tokens.push(Token::Quote("\"".to_string()));
tokens.push(Token::String(self.name.clone()));
tokens.push(Token::Quote("\"".to_string()));