Fix clippy 1.67

This commit is contained in:
jcamiel 2023-01-26 18:14:41 +01:00
parent eb34bb7ec7
commit 3575aef1fa
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
44 changed files with 250 additions and 286 deletions

View File

@ -36,7 +36,7 @@ pub fn read_to_string(filename: &str) -> Result<String, CliError> {
let mut contents = String::new();
return if let Err(e) = std::io::stdin().read_to_string(&mut contents) {
Err(CliError {
message: format!("Input stream can not be read - {}", e),
message: format!("Input stream can not be read - {e}"),
})
} else {
return Ok(contents);

View File

@ -95,7 +95,7 @@ fn log_request(request: Request) {
MultipartParam::FileParam(file_param) => {
let content_type =
if let Some(content_type) = file_param.value.content_type {
format!("; {}", content_type)
format!("; {content_type}")
} else {
"".to_string()
};

View File

@ -41,7 +41,7 @@ pub struct CliError {
impl From<Box<dyn Error>> for CliError {
fn from(e: Box<dyn Error>) -> Self {
Self {
message: format!("{:?}", e),
message: format!("{e:?}"),
}
}
}
@ -57,7 +57,7 @@ impl From<&str> for CliError {
impl From<String> for CliError {
fn from(e: String) -> Self {
Self {
message: format!("{:?}", e),
message: format!("{e:?}"),
}
}
}

View File

@ -418,7 +418,7 @@ pub fn parse_options(matches: &ArgMatches) -> Result<CliOptions, CliError> {
None => None,
Some(filename) => {
if !Path::new(&filename).is_file() {
let message = format!("File {} does not exist", filename);
let message = format!("File {filename} does not exist");
return Err(CliError { message });
} else {
Some(filename)
@ -429,7 +429,7 @@ pub fn parse_options(matches: &ArgMatches) -> Result<CliOptions, CliError> {
None => None,
Some(filename) => {
if !Path::new(&filename).is_file() {
let message = format!("File {} does not exist", filename);
let message = format!("File {filename} does not exist");
return Err(CliError { message });
} else {
Some(filename)
@ -440,7 +440,7 @@ pub fn parse_options(matches: &ArgMatches) -> Result<CliOptions, CliError> {
None => None,
Some(filename) => {
if !Path::new(&filename).is_file() {
let message = format!("File {} does not exist", filename);
let message = format!("File {filename} does not exist");
return Err(CliError { message });
} else {
Some(filename)

View File

@ -22,7 +22,7 @@ use crate::runner::Value;
pub fn parse(s: &str) -> Result<(String, Value), CliError> {
match s.find('=') {
None => Err(CliError {
message: format!("Missing value for variable {}!", s),
message: format!("Missing value for variable {s}!"),
}),
Some(index) => {
let (name, value) = s.split_at(index);

View File

@ -171,13 +171,13 @@ mod tests {
}
fn check_num(num: usize, expected: &str) {
let text = format!("&#{}", num);
let text = format!("&#{num}");
check(&text, expected);
let text = format!("&#{};", num);
let text = format!("&#{num};");
check(&text, expected);
let text = format!("&#x{:x}", num);
let text = format!("&#x{num:x}");
check(&text, expected);
let text = format!("&#x{:x};", num);
let text = format!("&#x{num:x};");
check(&text, expected);
}
@ -218,9 +218,9 @@ mod tests {
]
.iter()
{
check(&format!("&#{}", num), &format!("{}", char));
check(&format!("&#{} ", num), &format!("{} ", char));
check(&format!("&#{}X", num), &format!("{}X", char));
check(&format!("&#{num}"), &format!("{char}"));
check(&format!("&#{num} "), &format!("{char} "));
check(&format!("&#{num}X"), &format!("{char}X"));
}
// Format &#0001234 (without ending semi-colon)
@ -234,9 +234,9 @@ mod tests {
]
.iter()
{
check(&format!("&#{:07}", num), &format!("{}", char));
check(&format!("&#{:07} ", num), &format!("{} ", char));
check(&format!("&#{:07}X", num), &format!("{}X", char));
check(&format!("&#{num:07}"), &format!("{char}"));
check(&format!("&#{num:07} "), &format!("{char} "));
check(&format!("&#{num:07}X"), &format!("{char}X"));
}
// Format &#1234;
@ -250,9 +250,9 @@ mod tests {
]
.iter()
{
check(&format!("&#{};", num), &format!("{}", char));
check(&format!("&#{}; ", num), &format!("{} ", char));
check(&format!("&#{};X", num), &format!("{}X", char));
check(&format!("&#{num};"), &format!("{char}"));
check(&format!("&#{num}; "), &format!("{char} "));
check(&format!("&#{num};X"), &format!("{char}X"));
}
// Format &#0001234;
@ -266,9 +266,9 @@ mod tests {
]
.iter()
{
check(&format!("&#{:07};", num), &format!("{}", char));
check(&format!("&#{:07}; ", num), &format!("{} ", char));
check(&format!("&#{:07};X", num), &format!("{}X", char));
check(&format!("&#{num:07};"), &format!("{char}"));
check(&format!("&#{num:07}; "), &format!("{char} "));
check(&format!("&#{num:07};X"), &format!("{char}X"));
}
// Format &#x1abc
@ -282,9 +282,9 @@ mod tests {
]
.iter()
{
check(&format!("&#x{:x}", num), &format!("{}", char));
check(&format!("&#x{:x} ", num), &format!("{} ", char));
check(&format!("&#x{:x}X", num), &format!("{}X", char));
check(&format!("&#x{num:x}"), &format!("{char}"));
check(&format!("&#x{num:x} "), &format!("{char} "));
check(&format!("&#x{num:x}X"), &format!("{char}X"));
}
// Format &#x001abc
@ -298,9 +298,9 @@ mod tests {
]
.iter()
{
check(&format!("&#x{:06x}", num), &format!("{}", char));
check(&format!("&#x{:06x} ", num), &format!("{} ", char));
check(&format!("&#x{:06x}X", num), &format!("{}X", char));
check(&format!("&#x{num:06x}"), &format!("{char}"));
check(&format!("&#x{num:06x} "), &format!("{char} "));
check(&format!("&#x{num:06x}X"), &format!("{char}X"));
}
// Format &#x1abc;
@ -314,9 +314,9 @@ mod tests {
]
.iter()
{
check(&format!("&#x{:x};", num), &format!("{}", char));
check(&format!("&#x{:x}; ", num), &format!("{} ", char));
check(&format!("&#x{:x};X", num), &format!("{}X", char));
check(&format!("&#x{num:x};"), &format!("{char}"));
check(&format!("&#x{num:x}; "), &format!("{char} "));
check(&format!("&#x{num:x};X"), &format!("{char}X"));
}
// Format &#x001abc;
@ -330,9 +330,9 @@ mod tests {
]
.iter()
{
check(&format!("&#x{:06x};", num), &format!("{}", char));
check(&format!("&#x{:06x}; ", num), &format!("{} ", char));
check(&format!("&#x{:06x};X", num), &format!("{}X", char));
check(&format!("&#x{num:06x};"), &format!("{char}"));
check(&format!("&#x{num:06x}; "), &format!("{char} "));
check(&format!("&#x{num:06x};X"), &format!("{char}X"));
}
// Format &#x1ABC
@ -346,9 +346,9 @@ mod tests {
]
.iter()
{
check(&format!("&#x{:X}", num), &format!("{}", char));
check(&format!("&#x{:X} ", num), &format!("{} ", char));
check(&format!("&#x{:X}X", num), &format!("{}X", char));
check(&format!("&#x{num:X}"), &format!("{char}"));
check(&format!("&#x{num:X} "), &format!("{char} "));
check(&format!("&#x{num:X}X"), &format!("{char}X"));
}
// Format &#x001ABC
@ -362,9 +362,9 @@ mod tests {
]
.iter()
{
check(&format!("&#x{:06X}", num), &format!("{}", char));
check(&format!("&#x{:06X} ", num), &format!("{} ", char));
check(&format!("&#x{:06X}X", num), &format!("{}X", char));
check(&format!("&#x{num:06X}"), &format!("{char}"));
check(&format!("&#x{num:06X} "), &format!("{char} "));
check(&format!("&#x{num:06X}X"), &format!("{char}X"));
}
// Format &#x1ABC;
@ -378,9 +378,9 @@ mod tests {
]
.iter()
{
check(&format!("&#x{:X};", num), &format!("{}", char));
check(&format!("&#x{:X}; ", num), &format!("{} ", char));
check(&format!("&#x{:X};X", num), &format!("{}X", char));
check(&format!("&#x{num:X};"), &format!("{char}"));
check(&format!("&#x{num:X}; "), &format!("{char} "));
check(&format!("&#x{num:X};X"), &format!("{char}X"));
}
// Format &#x001ABC;
@ -394,9 +394,9 @@ mod tests {
]
.iter()
{
check(&format!("&#x{:06X};", num), &format!("{}", char));
check(&format!("&#x{:06X}; ", num), &format!("{} ", char));
check(&format!("&#x{:06X};X", num), &format!("{}X", char));
check(&format!("&#x{num:06X};"), &format!("{char}"));
check(&format!("&#x{num:06X}; "), &format!("{char} "));
check(&format!("&#x{num:06X};X"), &format!("{char}X"));
}
// Format &#X1abc;
@ -410,9 +410,9 @@ mod tests {
]
.iter()
{
check(&format!("&#X{:x};", num), &format!("{}", char));
check(&format!("&#X{:x}; ", num), &format!("{} ", char));
check(&format!("&#X{:x};X", num), &format!("{}X", char));
check(&format!("&#X{num:x};"), &format!("{char}"));
check(&format!("&#X{num:x}; "), &format!("{char} "));
check(&format!("&#X{num:x};X"), &format!("{char}X"));
}
// Format &#X001abc;
@ -426,9 +426,9 @@ mod tests {
]
.iter()
{
check(&format!("&#X{:06x};", num), &format!("{}", char));
check(&format!("&#X{:06x}; ", num), &format!("{} ", char));
check(&format!("&#X{:06x};X", num), &format!("{}X", char));
check(&format!("&#X{num:06x};"), &format!("{char}"));
check(&format!("&#X{num:06x}; "), &format!("{char} "));
check(&format!("&#X{num:06x};X"), &format!("{char}X"));
}
// Check invalid code points
@ -466,7 +466,7 @@ mod tests {
// Check triple adjacent charrefs
for e in ["&quot", "&#34", "&#x22", "&#X22"] {
// check(&e.repeat(3), "\"\"\"");
check(&format!("{};", e).repeat(3), "\"\"\"")
check(&format!("{e};").repeat(3), "\"\"\"")
}
// Check that the case is respected

View File

@ -87,7 +87,7 @@ impl Client {
let base_url = request.base_url()?;
if let Some(url) = self.get_follow_location(&response, &base_url) {
logger.debug("");
logger.debug(format!("=> Redirect to {}", url).as_str());
logger.debug(format!("=> Redirect to {url}").as_str());
logger.debug("");
request_spec = RequestSpec {
method: Method::Get,
@ -373,12 +373,12 @@ impl Client {
let url = if url.ends_with('?') {
url.to_string()
} else if url.contains('?') {
format!("{}&", url)
format!("{url}&")
} else {
format!("{}?", url)
format!("{url}?")
};
let s = self.url_encode_params(params);
format!("{}{}", url, s)
format!("{url}{s}")
}
}
@ -400,8 +400,7 @@ impl Client {
if request.get_header_values("Content-Type").is_empty() {
if let Some(ref s) = request.content_type {
list.append(format!("Content-Type: {}", s).as_str())
.unwrap();
list.append(format!("Content-Type: {s}").as_str()).unwrap();
} else {
// We remove default Content-Type headers added by curl because we want
// to explicitly manage this header.
@ -422,7 +421,7 @@ impl Client {
Some(ref u) => u.clone(),
None => format!("hurl/{}", clap::crate_version!()),
};
list.append(format!("User-Agent: {}", user_agent).as_str())
list.append(format!("User-Agent: {user_agent}").as_str())
.unwrap();
}
@ -430,7 +429,7 @@ impl Client {
let user = user.as_bytes();
let authorization = general_purpose::STANDARD.encode(user);
if request.get_header_values("Authorization").is_empty() {
list.append(format!("Authorization: Basic {}", authorization).as_str())
list.append(format!("Authorization: Basic {authorization}").as_str())
.unwrap();
}
}
@ -571,7 +570,7 @@ impl Client {
if let Ok(cookie) = Cookie::from_str(line) {
cookies.push(cookie);
} else {
eprintln!("warning: line <{}> can not be parsed as cookie", line);
eprintln!("warning: line <{line}> can not be parsed as cookie");
}
}
cookies
@ -580,7 +579,7 @@ impl Client {
/// Adds a cookie to the cookie jar.
pub fn add_cookie(&mut self, cookie: &Cookie, options: &ClientOptions) {
if options.verbosity.is_some() {
eprintln!("* add to cookie store: {}", cookie);
eprintln!("* add to cookie store: {cookie}");
}
self.handle
.cookie_list(cookie.to_string().as_str())
@ -630,7 +629,7 @@ impl Client {
/// Returns the redirect url.
fn get_redirect_url(location: &str, base_url: &str) -> String {
if location.starts_with('/') {
format!("{}{}", base_url, location)
format!("{base_url}{location}")
} else {
location.to_string()
}
@ -715,7 +714,7 @@ pub fn decode_header(data: &[u8]) -> Option<String> {
Err(_) => match ISO_8859_1.decode(data, DecoderTrap::Strict) {
Ok(s) => Some(s),
Err(_) => {
println!("Error decoding header both UTF-8 and ISO-8859-1 {:?}", data);
println!("Error decoding header both UTF-8 and ISO-8859-1 {data:?}");
None
}
},

View File

@ -120,7 +120,7 @@ impl ClientOptions {
}
if let Some(ref proxy) = self.proxy {
arguments.push("--proxy".to_string());
arguments.push(format!("'{}'", proxy));
arguments.push(format!("'{proxy}'"));
}
for resolve in self.resolves.iter() {
arguments.push("--resolve".to_string());
@ -132,11 +132,11 @@ impl ClientOptions {
}
if let Some(ref user) = self.user {
arguments.push("--user".to_string());
arguments.push(format!("'{}'", user));
arguments.push(format!("'{user}'"));
}
if let Some(ref user_agent) = self.user_agent {
arguments.push("--user-agent".to_string());
arguments.push(format!("'{}'", user_agent));
arguments.push(format!("'{user_agent}'"));
}
arguments
}

View File

@ -74,7 +74,7 @@ impl Request {
url.scheme(),
url.host().unwrap(),
if let Some(port) = url.port() {
format!(":{}", port)
format!(":{port}")
} else {
"".to_string()
}

View File

@ -112,15 +112,15 @@ impl fmt::Display for Method {
Method::Propfind => "PROPFIND",
Method::View => "VIEW",
};
write!(f, "{}", value)
write!(f, "{value}")
}
}
impl fmt::Display for MultipartParam {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
MultipartParam::Param(param) => write!(f, "{}", param),
MultipartParam::FileParam(param) => write!(f, "{}", param),
MultipartParam::Param(param) => write!(f, "{param}"),
MultipartParam::FileParam(param) => write!(f, "{param}"),
}
}
}

View File

@ -46,7 +46,7 @@ impl RequestSpec {
&& content_type.as_str() != "multipart/form-data"
{
arguments.push("-H".to_string());
arguments.push(format!("'Content-Type: {}'", content_type));
arguments.push(format!("'Content-Type: {content_type}'"));
}
} else if !self.body.bytes().is_empty() {
match self.body.clone() {
@ -97,14 +97,14 @@ impl RequestSpec {
} else {
format!("{}?{}", self.url, querystring)
};
arguments.push(format!("'{}'", url));
arguments.push(format!("'{url}'"));
arguments
}
}
fn encode_byte(b: u8) -> String {
format!("\\x{:02x}", b)
format!("\\x{b:02x}")
}
fn encode_bytes(b: Vec<u8>) -> String {
@ -140,22 +140,22 @@ impl Header {
let value = self.value.clone();
vec![
"-H".to_string(),
encode_shell_string(format!("{}: {}", name, value).as_str()),
encode_shell_string(format!("{name}: {value}").as_str()),
]
}
}
impl Param {
pub fn curl_arg_escape(&self) -> String {
let name = self.name.clone();
let value = escape_url(self.value.clone());
format!("{}={}", name, value)
let name = &self.name;
let value = escape_url(&self.value);
format!("{name}={value}")
}
pub fn curl_arg(&self) -> String {
let name = self.name.clone();
let value = self.value.clone();
format!("{}={}", name, value)
let name = &self.name;
let value = &self.value;
format!("{name}={value}")
}
}
@ -171,7 +171,7 @@ impl MultipartParam {
}) => {
let path = context_dir.get_path(filename);
let value = format!("@{};type={}", path.to_str().unwrap(), content_type);
format!("{}={}", name, value)
format!("{name}={value}")
}
}
}
@ -190,7 +190,7 @@ impl Body {
}
}
fn escape_url(s: String) -> String {
fn escape_url(s: &str) -> String {
percent_encoding::percent_encode(s.as_bytes(), percent_encoding::NON_ALPHANUMERIC).to_string()
}
@ -198,9 +198,9 @@ fn encode_shell_string(s: &str) -> String {
// $'...' form will be used to encode escaped sequence
if escape_mode(s) {
let escaped = escape_string(s);
format!("$'{}'", escaped)
format!("$'{escaped}'")
} else {
format!("'{}'", s)
format!("'{s}'")
}
}

View File

@ -44,7 +44,7 @@ impl fmt::Display for Version {
Version::Http11 => "HTTP/1.1",
Version::Http2 => "HTTP/2",
};
write!(f, "{}", value)
write!(f, "{value}")
}
}

View File

@ -36,39 +36,39 @@ pub fn libcurl_version_info() -> CurlVersionInfo {
libraries.push(s.to_string());
}
if let Some(s) = version.libz_version() {
libraries.push(format!("zlib/{}", s));
libraries.push(format!("zlib/{s}"));
}
if let Some(s) = version.brotli_version() {
libraries.push(format!("brotli/{}", s));
libraries.push(format!("brotli/{s}"));
}
if let Some(s) = version.zstd_version() {
libraries.push(format!("zstd/{}", s));
libraries.push(format!("zstd/{s}"));
}
if let Some(s) = version.ares_version() {
libraries.push(format!("c-ares/{}", s));
libraries.push(format!("c-ares/{s}"));
}
if let Some(s) = version.libidn_version() {
libraries.push(format!("libidn2/{}", s));
libraries.push(format!("libidn2/{s}"));
}
if let Some(s) = version.iconv_version_num() {
if s != 0 {
libraries.push(format!("iconv/{}", s));
libraries.push(format!("iconv/{s}"));
}
}
if let Some(s) = version.libssh_version() {
libraries.push(s.to_string());
}
if let Some(s) = version.nghttp2_version() {
libraries.push(format!("nghttp2/{}", s));
libraries.push(format!("nghttp2/{s}"));
}
if let Some(s) = version.quic_version() {
libraries.push(format!("quic/{}", s));
libraries.push(format!("quic/{s}"));
}
if let Some(s) = version.hyper_version() {
libraries.push(format!("hyper/{}", s));
libraries.push(format!("hyper/{s}"));
}
if let Some(s) = version.gsasl_version() {
libraries.push(format!("libgsal/{}", s));
libraries.push(format!("libgsal/{s}"));
}
// FIXME: some flags are not present in crates curl-rust.

View File

@ -56,7 +56,7 @@ pub fn natural(reader: &mut Reader) -> ParseResult<'static, usize> {
},
});
}
Ok(format!("{}{}", first_digit, s).parse().unwrap())
Ok(format!("{first_digit}{s}").parse().unwrap())
}
pub fn integer(reader: &mut Reader) -> ParseResult<'static, i64> {
@ -89,7 +89,7 @@ pub fn number(reader: &mut Reader) -> ParseResult<'static, Number> {
},
});
}
format!("{:0<18}", s).parse().unwrap()
format!("{s:0<18}").parse().unwrap()
} else {
0
};
@ -169,7 +169,7 @@ pub fn key_name(reader: &mut Reader) -> Result<String, Error> {
};
let s = reader.read_while(|c| c.is_alphanumeric() || *c == '_');
whitespace(reader);
Ok(format!("{}{}", first_char, s))
Ok(format!("{first_char}{s}"))
}
// key1.key2.key3

View File

@ -110,19 +110,19 @@ fn execute(
logger.debug(format!(" insecure: {}", cli_options.insecure).as_str());
if let Some(n) = cli_options.max_redirect {
logger.debug(format!(" max redirect: {}", n).as_str());
logger.debug(format!(" max redirect: {n}").as_str());
}
if let Some(proxy) = &cli_options.proxy {
logger.debug(format!(" proxy: {}", proxy).as_str());
logger.debug(format!(" proxy: {proxy}").as_str());
}
logger.debug(format!(" retry: {}", cli_options.retry).as_str());
if let Some(n) = cli_options.retry_max_count {
logger.debug(format!(" retry max count: {}", n).as_str());
logger.debug(format!(" retry max count: {n}").as_str());
}
if !cli_options.variables.is_empty() {
logger.debug_important("Variables:");
for (name, value) in cli_options.variables.clone() {
logger.debug(format!(" {}: {}", name, value).as_str());
logger.debug(format!(" {name}: {value}").as_str());
}
}
if let Some(to_entry) = cli_options.to_entry {
@ -233,10 +233,7 @@ fn main() {
for (current, filename) in filenames.iter().enumerate() {
if filename != "-" && !Path::new(filename).exists() {
let message = format!(
"hurl: cannot access '{}': No such file or directory",
filename
);
let message = format!("hurl: cannot access '{filename}': No such file or directory");
exit_with_error(&message, EXIT_ERROR_PARSING, &base_logger);
}
let content = cli::read_to_string(filename);
@ -317,16 +314,16 @@ fn main() {
let source = if filename.as_str() == "-" {
"".to_string()
} else {
format!("for file {}", filename).to_string()
format!("for file {filename}").to_string()
};
logger.warning(format!("No entry have been executed {}", source).as_str());
logger.warning(format!("No entry have been executed {source}").as_str());
};
}
if matches!(cli_options.output_type, OutputType::Json) {
let json_result = hurl_result.to_json(&content);
let serialized = serde_json::to_string(&json_result).unwrap();
let s = format!("{}\n", serialized);
let s = format!("{serialized}\n");
let result = write_output(&s.into_bytes(), &cli_options.output);
unwrap_or_exit(result, EXIT_ERROR_UNDEFINED, &base_logger);
}
@ -337,7 +334,7 @@ fn main() {
}
if let Some(filename) = cli_options.junit_file.clone() {
base_logger.debug(format!("Writing Junit report to {}", filename).as_str());
base_logger.debug(format!("Writing Junit report to {filename}").as_str());
let result = report::create_junit_report(filename, testcases);
unwrap_or_exit(result, EXIT_ERROR_UNDEFINED, &base_logger);
}
@ -392,7 +389,7 @@ fn exit_code(hurl_results: &[HurlResult]) -> i32 {
fn format_html(input_file: &str, dir_path: &Path) -> Result<(), CliError> {
let relative_input_file = canonicalize_filename(input_file);
let absolute_input_file = dir_path.join(format!("{}.html", relative_input_file));
let absolute_input_file = dir_path.join(format!("{relative_input_file}.html"));
let parent = absolute_input_file.parent().expect("a parent");
std::fs::create_dir_all(parent).unwrap();
@ -499,7 +496,7 @@ fn get_summary(duration: u128, hurl_results: &[HurlResult]) -> String {
let mut s =
"--------------------------------------------------------------------------------\n"
.to_string();
s.push_str(format!("Executed files: {}\n", total).as_str());
s.push_str(format!("Executed files: {total}\n").as_str());
s.push_str(
format!(
"Succeeded files: {} ({:.1}%)\n",
@ -516,7 +513,7 @@ fn get_summary(duration: u128, hurl_results: &[HurlResult]) -> String {
)
.as_str(),
);
s.push_str(format!("Duration: {} ms\n", duration).as_str());
s.push_str(format!("Duration: {duration} ms\n").as_str());
s
}

View File

@ -168,13 +168,7 @@ fn create_html_index(now: &str, hurl_results: &[HTMLResult]) -> String {
</table>
</body>
</html>
"#,
now = now,
count_total = count_total,
count_success = count_success,
percentage_success = percentage_success,
count_failure = count_failure,
percentage_failure = percentage_failure
"#
)
}
@ -194,11 +188,7 @@ fn create_html_table_row(result: &HTMLResult) -> String {
<td>{status}</td>
<td>{duration_in_s}</td>
</tr>
"#,
status = status,
duration_in_ms = duration_in_ms,
filename = filename,
duration_in_s = duration_in_s
"#
)
}

View File

@ -101,14 +101,14 @@ pub fn create_report(filename: String, testcases: Vec<Testcase>) -> Result<(), C
Ok(f) => f,
Err(e) => {
return Err(CliError {
message: format!("Failed to produce junit report: {:?}", e),
message: format!("Failed to produce junit report: {e:?}"),
});
}
};
match report.write(file) {
Ok(_) => Ok(()),
Err(e) => Err(CliError {
message: format!("Failed to produce junit report: {:?}", e),
message: format!("Failed to produce junit report: {e:?}"),
}),
}
}

View File

@ -117,7 +117,7 @@ mod test {
let mut buffer = Vec::new();
let content = "";
Testcase::from_hurl_result(&hurl_result, &content)
Testcase::from_hurl_result(&hurl_result, content)
.to_xml()
.write(&mut buffer)
.unwrap();
@ -154,7 +154,7 @@ HTTP/1.0 200
cookies: vec![],
};
let mut buffer = Vec::new();
Testcase::from_hurl_result(&hurl_result, &content)
Testcase::from_hurl_result(&hurl_result, content)
.to_xml()
.write(&mut buffer)
.unwrap();

View File

@ -68,7 +68,7 @@ pub fn run(
if let Ok(cookie) = http::Cookie::from_str(s.as_str()) {
http_client.add_cookie(&cookie, &client_options);
} else {
logger.warning(format!("Cookie string can not be parsed: '{}'", s).as_str());
logger.warning(format!("Cookie string can not be parsed: '{s}'").as_str());
}
}
if cookie_storage_clear(&entry.request) {
@ -282,7 +282,7 @@ fn log_request_spec(request: &http::RequestSpec, logger: &Logger) {
}
if let Some(s) = &request.content_type {
logger.debug("");
logger.debug(format!("Implicit content-type={}", s).as_str());
logger.debug(format!("Implicit content-type={s}").as_str());
}
logger.debug("");
}

View File

@ -71,25 +71,25 @@ 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)
format!("you must set the variable {name}")
}
RunnerError::HttpConnection { message, .. } => message.to_string(),
RunnerError::CouldNotResolveProxyName => "could not resolve proxy name".to_string(),
RunnerError::CouldNotResolveHost(host) => format!("could not resolve host <{}>", host),
RunnerError::CouldNotResolveHost(host) => format!("could not resolve host <{host}>"),
RunnerError::FailToConnect => "fail to connect".to_string(),
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::AssertVersion { actual, .. } => format!("actual value is <{}>", actual),
RunnerError::AssertStatus { actual, .. } => format!("actual value is <{}>", actual),
RunnerError::AssertVersion { actual, .. } => format!("actual value is <{actual}>"),
RunnerError::AssertStatus { actual, .. } => format!("actual value is <{actual}>"),
RunnerError::PredicateValue(value) => {
format!("actual value is <{}>", value)
format!("actual value is <{value}>")
}
RunnerError::InvalidRegex {} => "regex expression is not valid".to_string(),
RunnerError::FileReadAccess { value } => format!("file {} can not be read", value),
RunnerError::FileReadAccess { value } => format!("file {value} can not be read"),
RunnerError::QueryInvalidXml { .. } => {
"the HTTP response is not a valid XML".to_string()
}
@ -103,25 +103,25 @@ impl Error for runner::Error {
"the XPath expression is not valid".to_string()
}
RunnerError::AssertHeaderValueError { actual } => {
format!("actual value is <{}>", actual)
format!("actual value is <{actual}>")
}
RunnerError::AssertBodyValueError { actual, .. } => {
format!("actual value is <{}>", actual)
format!("actual value is <{actual}>")
}
RunnerError::QueryInvalidJson { .. } => {
"the HTTP response is not a valid JSON".to_string()
}
RunnerError::QueryInvalidJsonpathExpression { value } => {
format!("the JSONPath expression '{}' is not valid", value)
format!("the JSONPath expression '{value}' is not valid")
}
RunnerError::PredicateType { .. } => {
"predicate type inconsistent with value return by query".to_string()
}
RunnerError::InvalidDecoding { charset } => {
format!("the body can not be decoded with charset '{}'", charset)
format!("the body can not be decoded with charset '{charset}'")
}
RunnerError::InvalidCharset { charset } => {
format!("the charset '{}' is not valid", charset)
format!("the charset '{charset}' is not valid")
}
RunnerError::AssertFailure {
actual,
@ -134,23 +134,23 @@ impl Error for runner::Error {
} else {
""
};
format!("actual: {}\nexpected: {}{}", actual, expected, additional)
format!("actual: {actual}\nexpected: {expected}{additional}")
}
RunnerError::VariableNotDefined { name } => {
format!("you must set the variable {}", name)
format!("you must set the variable {name}")
}
RunnerError::UnrenderableVariable { value } => {
format!("value {} can not be rendered", value)
format!("value {value} can not be rendered")
}
RunnerError::NoQueryResult { .. } => "The query didn't return any result".to_string(),
RunnerError::UnsupportedContentEncoding(algorithm) => {
format!("compression {} is not supported", algorithm)
format!("compression {algorithm} is not supported")
}
RunnerError::CouldNotUncompressResponse(algorithm) => {
format!("could not uncompress response with {}", algorithm)
format!("could not uncompress response with {algorithm}")
}
RunnerError::InvalidJson { value } => {
format!("actual value is <{}>", value)
format!("actual value is <{value}>")
}
RunnerError::UnauthorizedFileAccess { path } => {
format!(
@ -160,7 +160,7 @@ impl Error for runner::Error {
}
RunnerError::FilterMissingInput { .. } => "missing value to apply filter".to_string(),
RunnerError::FilterInvalidInput(message) => {
format!("invalid filter input: {}", message)
format!("invalid filter input: {message}")
}
RunnerError::FilterRegexNoCapture { .. } => "capture not found".to_string(),
}
@ -182,7 +182,7 @@ impl From<HttpError> for RunnerError {
description,
url,
} => RunnerError::HttpConnection {
message: format!("({}) {}", code, description),
message: format!("({code}) {description}"),
url,
},
HttpError::StatuslineIsMissing { url } => RunnerError::HttpConnection {

View File

@ -132,7 +132,7 @@ pub fn run(
logger.debug_important(
"------------------------------------------------------------------------------",
);
logger.debug_important(format!("Executing entry {}", entry_index).as_str());
logger.debug_important(format!("Executing entry {entry_index}").as_str());
warn_deprecated(entry, &logger);
@ -204,11 +204,7 @@ pub fn run(
let delay = retry_interval.as_millis();
logger.debug("");
logger.debug_important(
format!(
"Retry entry {} (x{} pause {} ms)",
entry_index, retry_count, delay
)
.as_str(),
format!("Retry entry {entry_index} (x{retry_count} pause {delay} ms)").as_str(),
);
retry_count += 1;
thread::sleep(retry_interval);

View File

@ -33,7 +33,7 @@ pub fn eval_json_value(
JsonValue::Number(s) => Ok(s.clone()),
JsonValue::String(template) => {
let s = eval_json_template(template, variables)?;
Ok(format!("\"{}\"", s))
Ok(format!("\"{s}\""))
}
JsonValue::Boolean(v) => Ok(v.to_string()),
JsonValue::List { space0, elements } => {

View File

@ -93,9 +93,9 @@ struct AssertResult {
impl Value {
pub fn display(&self) -> String {
match self {
Value::Bool(v) => format!("bool <{}>", v),
Value::Integer(v) => format!("int <{}>", v),
Value::String(v) => format!("string <{}>", v),
Value::Bool(v) => format!("bool <{v}>"),
Value::Integer(v) => format!("int <{v}>"),
Value::String(v) => format!("string <{v}>"),
Value::Float(f) => format!("float <{}>", format_float(*f)),
Value::List(values) => format!(
"[{}]",
@ -105,7 +105,7 @@ impl Value {
.collect::<Vec<String>>()
.join(", ")
),
Value::Nodeset(n) => format!("nodeset of size <{}>", n),
Value::Nodeset(n) => format!("nodeset of size <{n}>"),
Value::Object(_) => "object".to_string(),
Value::Bytes(value) => format!("byte array <{}>", hex::encode(value)),
Value::Null => "null".to_string(),
@ -137,24 +137,24 @@ fn eval_predicate_func(
impl Value {
pub fn expected(&self) -> String {
match self {
Value::Bool(value) => format!("bool <{}>", value),
Value::Bool(value) => format!("bool <{value}>"),
Value::Bytes(values) => format!("list of size {}", values.len()),
Value::Float(f) => format!("float <{}>", format_float(*f)),
Value::Integer(value) => format!("integer <{}>", value),
Value::Integer(value) => format!("integer <{value}>"),
Value::List(value) => format!("list of size {}", value.len()),
Value::Nodeset(size) => format!("list of size {}", size),
Value::Nodeset(size) => format!("list of size {size}"),
Value::Null => "null".to_string(),
Value::Object(values) => format!("list of size {}", values.len()),
Value::String(value) => format!("string <{}>", value),
Value::String(value) => format!("string <{value}>"),
Value::Unit => "something".to_string(),
Value::Regex(value) => format!("regex <{}>", value),
Value::Regex(value) => format!("regex <{value}>"),
}
}
}
fn format_float(value: f64) -> String {
if value.fract() < f64::EPSILON {
format!("{}.0", value)
format!("{value}.0")
} else {
value.to_string()
}
@ -194,25 +194,25 @@ fn expected(
} else {
panic!();
};
Ok(format!("count equals to <{}>", expected))
Ok(format!("count equals to <{expected}>"))
}
PredicateFuncValue::StartWith {
value: expected, ..
} => {
let expected = eval_predicate_value_template(expected, variables)?;
Ok(format!("starts with string <{}>", expected))
Ok(format!("starts with string <{expected}>"))
}
PredicateFuncValue::EndWith {
value: expected, ..
} => {
let expected = eval_predicate_value_template(expected, variables)?;
Ok(format!("ends with string <{}>", expected))
Ok(format!("ends with string <{expected}>"))
}
PredicateFuncValue::Contain {
value: expected, ..
} => {
let expected = eval_predicate_value_template(expected, variables)?;
Ok(format!("contains string <{}>", expected))
Ok(format!("contains string <{expected}>"))
}
PredicateFuncValue::Include { value, .. } => {
let value = eval_predicate_value(value, variables)?;
@ -222,7 +222,7 @@ fn expected(
value: expected, ..
} => {
let expected = eval_predicate_value_template(expected, variables)?;
Ok(format!("matches regex <{}>", expected))
Ok(format!("matches regex <{expected}>"))
}
PredicateFuncValue::IsInteger {} => Ok("integer".to_string()),
PredicateFuncValue::IsFloat {} => Ok("float".to_string()),
@ -314,7 +314,7 @@ fn eval_something(
_ => Ok(AssertResult {
success: false,
actual: value.display(),
expected: format!("count equals to <{}>", expected_value),
expected: format!("count equals to <{expected_value}>"),
type_mismatch: true,
}),
},
@ -433,13 +433,13 @@ fn eval_something(
Value::String(actual) => Ok(AssertResult {
success: regex.is_match(actual.as_str()),
actual: value.display(),
expected: format!("matches regex <{}>", regex),
expected: format!("matches regex <{regex}>"),
type_mismatch: false,
}),
_ => Ok(AssertResult {
success: false,
actual: value.display(),
expected: format!("matches regex <{}>", regex),
expected: format!("matches regex <{regex}>"),
type_mismatch: true,
}),
}

View File

@ -115,7 +115,7 @@ pub fn eval_query(
assert: false,
}),
Err(xpath::XpathError::Unsupported {}) => {
panic!("Unsupported xpath {}", value); // good usecase for panic - I could nmot reporduce this usecase myself
panic!("Unsupported xpath {value}"); // good usecase for panic - I could nmot reporduce this usecase myself
}
}
}
@ -623,9 +623,7 @@ pub mod tests {
},
};
assert_eq!(
eval_query(&query, &variables, &response.clone())
.unwrap()
.unwrap(),
eval_query(&query, &variables, &response).unwrap().unwrap(),
Value::String("DQAAAKEaem_vYg".to_string())
);
@ -652,9 +650,7 @@ pub mod tests {
},
};
assert_eq!(
eval_query(&query, &variables, &response.clone())
.unwrap()
.unwrap(),
eval_query(&query, &variables, &response).unwrap().unwrap(),
Value::String("/accounts".to_string())
);
@ -681,9 +677,7 @@ pub mod tests {
},
};
assert_eq!(
eval_query(&query, &variables, &response.clone())
.unwrap()
.unwrap(),
eval_query(&query, &variables, &response).unwrap().unwrap(),
Value::Unit
);

View File

@ -57,7 +57,7 @@ pub fn eval_request(
let user_password = user_password.as_bytes();
let authorization = general_purpose::STANDARD.encode(user_password);
let name = "Authorization".to_string();
let value = format!("Basic {}", authorization);
let value = format!("Basic {authorization}");
let header = http::Header { name, value };
headers.push(header);
}

View File

@ -105,7 +105,7 @@ pub fn eval_asserts(
"[{}]",
actuals
.iter()
.map(|v| format!("\"{}\"", v))
.map(|v| format!("\"{v}\""))
.collect::<Vec<String>>()
.join(", ")
);

View File

@ -69,22 +69,22 @@ impl fmt::Display for Value {
format!("[{}]", values.join(","))
}
Value::Object(_) => "Object()".to_string(),
Value::Nodeset(x) => format!("Nodeset{:?}", x),
Value::Nodeset(x) => format!("Nodeset{x:?}"),
Value::Bytes(v) => format!("hex, {};", hex::encode(v)),
Value::Null => "null".to_string(),
Value::Unit => "Unit".to_string(),
Value::Regex(x) => {
let s = str::replace(x.as_str(), "/", "\\/");
format!("/{}/", s)
format!("/{s}/")
}
};
write!(f, "{}", value)
write!(f, "{value}")
}
}
fn format_float(value: f64) -> String {
if value.fract() < f64::EPSILON {
format!("{}.0", value)
format!("{value}.0")
} else {
value.to_string()
}

View File

@ -297,7 +297,7 @@ impl<'a> Logger<'a> {
}
fn log_info(message: &str) {
eprintln!("{}", message);
eprintln!("{message}");
}
fn log_debug(message: &str) {
@ -312,7 +312,7 @@ fn log_debug_no_color(message: &str) {
if message.is_empty() {
eprintln!("*");
} else {
eprintln!("* {}", message);
eprintln!("* {message}");
}
}
@ -328,7 +328,7 @@ fn log_debug_curl_no_color(message: &str) {
if message.is_empty() {
eprintln!("**");
} else {
eprintln!("** {}", message);
eprintln!("** {message}");
}
}
@ -357,7 +357,7 @@ fn log_debug_header_in(name: &str, value: &str) {
}
fn log_debug_header_in_no_color(name: &str, value: &str) {
eprintln!("< {}: {}", name, value)
eprintln!("< {name}: {value}")
}
fn log_debug_header_out(name: &str, value: &str) {
@ -365,7 +365,7 @@ fn log_debug_header_out(name: &str, value: &str) {
}
fn log_debug_header_out_no_color(name: &str, value: &str) {
eprintln!("> {}: {}", name, value)
eprintln!("> {name}: {value}")
}
fn log_debug_method_version_out(line: &str) {
@ -373,7 +373,7 @@ fn log_debug_method_version_out(line: &str) {
}
fn log_debug_method_version_out_no_color(line: &str) {
eprintln!("> {}", line)
eprintln!("> {line}")
}
fn log_debug_status_version_in(line: &str) {
@ -381,7 +381,7 @@ fn log_debug_status_version_in(line: &str) {
}
fn log_debug_status_version_in_no_color(line: &str) {
eprintln!("< {}", line)
eprintln!("< {line}")
}
fn log_warning(message: &str) {
@ -389,7 +389,7 @@ fn log_warning(message: &str) {
}
fn log_warning_no_color(message: &str) {
eprintln!("warning: {}", message);
eprintln!("warning: {message}");
}
fn log_error(message: &str) {
@ -397,7 +397,7 @@ fn log_error(message: &str) {
}
fn log_error_no_color(message: &str) {
eprintln!("error: {}", message);
eprintln!("error: {message}");
}
fn log_error_rich(filename: &str, content: &str, error: &dyn Error) {
@ -415,7 +415,7 @@ fn log_capture(name: &str, value: &Value) {
}
fn log_capture_no_color(name: &str, value: &Value) {
eprintln!("* {}: {}", name, value)
eprintln!("* {name}: {value}")
}
fn log_test_running(filename: &str, current: usize, total: usize) {
@ -429,7 +429,7 @@ fn log_test_running(filename: &str, current: usize, total: usize) {
}
fn log_test_running_no_color(filename: &str, current: usize, total: usize) {
eprintln!("{}: Running [{}/{}]", filename, current, total)
eprintln!("{filename}: Running [{current}/{total}]")
}
fn log_test_completed(result: &HurlResult) {
@ -539,18 +539,14 @@ fn error_string(filename: &str, content: &str, error: &dyn Error, colored: bool)
};
let width = line_number_size;
let mut line_number = format!(
"{line_number:>width$}",
line_number = line_number,
width = width
);
let mut line_number = format!("{line_number:>width$}");
if colored {
line_number = line_number.blue().bold().to_string();
}
let line = if line.is_empty() {
line
} else {
format!(" {}", line)
format!(" {line}")
};
format!(
@ -577,7 +573,7 @@ fn add_line_prefix(s: &str, prefix: &str, colored: bool) -> String {
if colored {
format!("{}{}", prefix, line.red().bold())
} else {
format!("{}{}", prefix, line)
format!("{prefix}{line}")
}
})
.collect::<Vec<String>>()

View File

@ -785,7 +785,7 @@ fn test_error_fail_to_connect() {
} = error
{
assert_eq!(code, 7);
eprintln!("description={}", description);
eprintln!("description={description}");
assert!(description.starts_with("Failed to connect to localhost port 9999"));
assert_eq!(url, "http://localhost:8000/hello");
}
@ -854,8 +854,7 @@ fn test_error_ssl() {
];
assert!(
descriptions.contains(&description),
"actual description is {}",
description
"actual description is {description}"
);
assert_eq!(url, "https://localhost:8001/hello");
}
@ -949,7 +948,7 @@ fn test_connect_timeout() {
url,
} = error
{
eprintln!("description={}", description);
eprintln!("description={description}");
// TODO: remove the 7 / "Couldn't connect to server" case
// On Linux/Windows libcurl version, the correct error message
// is 28 / "Connection timeout" | "Connection timed out"
@ -1239,9 +1238,9 @@ fn test_version() {
let curl_version = std::str::from_utf8(&output.stdout).unwrap();
let index = curl_version.find("libcurl").expect("libcurl substring");
let expected_version = &curl_version[index..];
eprintln!("{:?}", expected_version);
eprintln!("{expected_version:?}");
let versions = libcurl_version_info();
eprintln!("{:?}", versions);
eprintln!("{versions:?}");
}
// This test function can be used to reproduce bug

View File

@ -123,11 +123,7 @@ fn test_hello() {
let content = "";
let filename = "filename";
let mut builder = LoggerBuilder::new();
let logger = builder
.filename(filename)
.content(&content)
.build()
.unwrap();
let logger = builder.filename(filename).content(content).build().unwrap();
let source_info = SourceInfo {
start: Pos { line: 1, column: 1 },

View File

@ -38,7 +38,7 @@ impl fmt::Display for Method {
Method::Propfind => "PROPFIND",
Method::View => "VIEW",
};
write!(f, "{}", s)
write!(f, "{s}")
}
}
@ -57,7 +57,7 @@ impl fmt::Display for VersionValue {
VersionValue::VersionAny => "HTTP",
VersionValue::VersionAnyLegacy => "HTTP/*",
};
write!(f, "{}", s)
write!(f, "{s}")
}
}
@ -71,7 +71,7 @@ impl fmt::Display for StatusValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
StatusValue::Any => write!(f, "*"),
StatusValue::Specific(v) => write!(f, "{}", v),
StatusValue::Specific(v) => write!(f, "{v}"),
}
}
}
@ -82,7 +82,7 @@ impl fmt::Display for Template {
for element in self.elements.iter() {
buffer.push_str(element.to_string().as_str());
}
write!(f, "{}", buffer)
write!(f, "{buffer}")
}
}
@ -90,9 +90,9 @@ impl fmt::Display for TemplateElement {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
TemplateElement::String { value, .. } => value.clone(),
TemplateElement::Expression(value) => format!("{{{{{}}}}}", value),
TemplateElement::Expression(value) => format!("{{{{{value}}}}}"),
};
write!(f, "{}", s)
write!(f, "{s}")
}
}
@ -112,10 +112,10 @@ impl fmt::Display for CookiePath {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut buf = self.name.to_string();
if let Some(attribute) = &self.attribute {
let s = format!("[{}]", attribute);
let s = format!("[{attribute}]");
buf.push_str(s.as_str());
}
write!(f, "{}", buf)
write!(f, "{buf}")
}
}
@ -131,7 +131,7 @@ impl fmt::Display for CookieAttribute {
CookieAttributeName::HttpOnly(_) => "HttpOnly",
CookieAttributeName::SameSite(_) => "SameSite",
};
write!(f, "{}", s)
write!(f, "{s}")
}
}
@ -171,7 +171,7 @@ impl fmt::Display for MultilineString {
format!("{}{}", graphql.value, var)
}
};
write!(f, "{}", body)
write!(f, "{body}")
}
}

View File

@ -76,9 +76,9 @@ pub struct ObjectElement {
impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Value::Expression(expr) => format!("{{{{{}}}}}", expr),
Value::Expression(expr) => format!("{{{{{expr}}}}}"),
Value::Number(s) => s.to_string(),
Value::String(template) => format!("\"{}\"", template),
Value::String(template) => format!("\"{template}\""),
Value::Boolean(value) => {
if *value {
"true".to_string()
@ -102,7 +102,7 @@ impl fmt::Display for Value {
}
Value::Null { .. } => "null".to_string(),
};
write!(f, "{}", s)
write!(f, "{s}")
}
}
@ -112,7 +112,7 @@ impl fmt::Display for ListElement {
s.push_str(self.space0.as_str());
s.push_str(self.value.to_string().as_str());
s.push_str(self.space1.as_str());
write!(f, "{}", s)
write!(f, "{s}")
}
}
@ -128,14 +128,14 @@ impl fmt::Display for ObjectElement {
s.push_str(self.space2.as_str());
s.push_str(self.value.to_string().as_str());
s.push_str(self.space3.as_str());
write!(f, "{}", s)
write!(f, "{s}")
}
}
impl Value {
pub fn encoded(&self) -> String {
match self {
Value::Expression(expr) => format!("{{{{{}}}}}", expr),
Value::Expression(expr) => format!("{{{{{expr}}}}}"),
Value::Number(s) => s.to_string(),
Value::String(template) => template.encoded(),
Value::Boolean(value) => {
@ -207,7 +207,7 @@ impl TemplateElement {
fn encoded(&self) -> String {
match self {
TemplateElement::String { encoded, .. } => encoded.to_string(),
TemplateElement::Expression(expr) => format!("{{{{{}}}}}", expr),
TemplateElement::Expression(expr) => format!("{{{{{expr}}}}}"),
}
}
}

View File

@ -60,7 +60,7 @@ impl Error for parser::Error {
ParseError::UrlIllegalCharacter(_) => "Parsing URL".to_string(),
ParseError::Multiline => "Parsing multiline".to_string(),
ParseError::GraphQlVariables => "Parsing GraphQL variables".to_string(),
_ => format!("{:?}", self),
_ => format!("{self:?}"),
}
}
@ -75,7 +75,7 @@ impl Error for parser::Error {
ParseError::Version { .. } => "HTTP version must be HTTP, HTTP/1.0, HTTP/1.1 or HTTP/2".to_string(),
ParseError::Status { .. } => "HTTP status code is not valid".to_string(),
ParseError::Filename { .. } => "expecting a filename".to_string(),
ParseError::Expecting { value } => format!("expecting '{}'", value),
ParseError::Expecting { value } => format!("expecting '{value}'"),
ParseError::Space { .. } => "expecting a space".to_string(),
ParseError::RequestSectionName { name }
=> format!("the section is not valid. {}", did_you_mean(
@ -95,7 +95,7 @@ impl Error for parser::Error {
ParseError::Json { .. } => "JSON error".to_string(),
ParseError::Predicate { .. } => "expecting a predicate".to_string(),
ParseError::PredicateValue { .. } => "invalid predicate value".to_string(),
ParseError::RegexExpr { message } => format!("invalid Regex expression: {}", message),
ParseError::RegexExpr { message } => format!("invalid Regex expression: {message}"),
ParseError::DuplicateSection { .. } => "the section is already defined".to_string(),
ParseError::RequestSection { .. } => {
"this is not a valid section for a request".to_string()
@ -110,10 +110,10 @@ impl Error for parser::Error {
ParseError::OddNumberOfHexDigits { .. } => {
"expecting an even number of hex digits".to_string()
}
ParseError::UrlIllegalCharacter(c) => format!("illegal character <{}>", c),
ParseError::UrlIllegalCharacter(c) => format!("illegal character <{c}>"),
ParseError::Multiline => "the multiline is not valid".to_string(),
ParseError::GraphQlVariables => "GraphQL variables is not a valid JSON object".to_string(),
_ => format!("{:?}", self),
_ => format!("{self:?}"),
}
}
@ -121,7 +121,7 @@ impl Error for parser::Error {
fn did_you_mean(valid_values: &[&str], actual: &str, default: &str) -> String {
if let Some(suggest) = suggestion(valid_values, actual) {
format!("Did you mean {}?", suggest)
format!("Did you mean {suggest}?")
} else {
default.to_string()
}

View File

@ -50,9 +50,7 @@ fn format_standalone(hurl_file: HurlFile) -> String {
{body}
</body>
</html>
"#,
css = css,
body = body
"#
)
}
@ -138,7 +136,7 @@ impl Htmlable for Response {
impl Htmlable for Method {
fn to_html(&self) -> String {
format!("<span class=\"method\">{}</span>", self)
format!("<span class=\"method\">{self}</span>")
}
}
@ -894,9 +892,9 @@ impl Htmlable for MultilineString {
format!("{}\n", self.lang())
}
};
let body = format!("```{}{}```", lang, self);
let body = format!("```{lang}{self}```");
let body = multilines(&body);
format!("<span class=\"multiline\">{}</span>", body)
format!("<span class=\"multiline\">{body}</span>")
}
}
@ -929,25 +927,25 @@ impl Htmlable for Bytes {
impl Htmlable for String {
fn to_html(&self) -> String {
format!("<span class=\"string\">{}</span>", self)
format!("<span class=\"string\">{self}</span>")
}
}
impl Htmlable for &str {
fn to_html(&self) -> String {
format!("<span class=\"string\">{}</span>", self)
format!("<span class=\"string\">{self}</span>")
}
}
impl Htmlable for bool {
fn to_html(&self) -> String {
format!("<span class=\"boolean\">{}</span>", self)
format!("<span class=\"boolean\">{self}</span>")
}
}
impl Htmlable for u64 {
fn to_html(&self) -> String {
format!("<span class=\"number\">{}</span>", self)
format!("<span class=\"number\">{self}</span>")
}
}
@ -959,13 +957,13 @@ impl Htmlable for Float {
impl Htmlable for i64 {
fn to_html(&self) -> String {
format!("<span class=\"number\">{}</span>", self)
format!("<span class=\"number\">{self}</span>")
}
}
impl Htmlable for usize {
fn to_html(&self) -> String {
format!("<span class=\"number\">{}</span>", self)
format!("<span class=\"number\">{self}</span>")
}
}
@ -1062,7 +1060,7 @@ impl Htmlable for Hex {
impl Htmlable for Regex {
fn to_html(&self) -> String {
let s = str::replace(self.inner.as_str(), "/", "\\/");
format!("<span class=\"regex\">/{}/</span>", s)
format!("<span class=\"regex\">/{s}/</span>")
}
}
@ -1087,7 +1085,7 @@ impl Template {
for element in self.elements.iter() {
let elem_str = match element {
TemplateElement::String { encoded, .. } => encoded.to_string(),
TemplateElement::Expression(expr) => format!("{{{{{}}}}}", expr),
TemplateElement::Expression(expr) => format!("{{{{{expr}}}}}"),
};
s.push_str(elem_str.as_str())
}

View File

@ -206,7 +206,7 @@ pub fn number_value(reader: &mut Reader) -> ParseResult<'static, JsonValue> {
},
});
} else {
format!(".{}", digits)
format!(".{digits}")
}
}
Err(_) => "".to_string(),
@ -222,14 +222,13 @@ pub fn number_value(reader: &mut Reader) -> ParseResult<'static, JsonValue> {
},
};
let exponent_digits = reader.read_while(|c| c.is_ascii_digit());
format!("e{}{}", exponent_sign, exponent_digits)
format!("e{exponent_sign}{exponent_digits}")
} else {
"".to_string()
};
Ok(JsonValue::Number(format!(
"{}{}{}{}",
sign, integer, fraction, exponent
"{sign}{integer}{fraction}{exponent}"
)))
}

View File

@ -226,7 +226,7 @@ pub fn try_literals(s1: &str, s2: &str, reader: &mut Reader) -> ParseResult<'sta
pos: start.pos,
recoverable: true,
inner: ParseError::Expecting {
value: format!("<{}> or <{}>", s1, s2),
value: format!("<{s1}> or <{s2}>"),
},
})
}
@ -453,7 +453,7 @@ pub fn natural(reader: &mut Reader) -> ParseResult<'static, u64> {
},
});
}
Ok(format!("{}{}", first_digit, s).parse().unwrap())
Ok(format!("{first_digit}{s}").parse().unwrap())
}
pub fn integer(reader: &mut Reader) -> ParseResult<'static, i64> {
@ -496,7 +496,7 @@ pub fn float(reader: &mut Reader) -> ParseResult<'static, Float> {
},
});
}
let value = format!("{}{}.{}", sign, nat, s).parse().unwrap();
let value = format!("{sign}{nat}.{s}").parse().unwrap();
let encoded = reader.from(start);
Ok(Float { value, encoded })
}

View File

@ -944,7 +944,7 @@ mod tests {
fn test_option_insecure_error() {
let mut reader = Reader::init("insecure: error");
let error = option_insecure(&mut reader).err().unwrap();
assert_eq!(error.recoverable, false)
assert!(!error.recoverable)
}
#[test]
@ -1023,7 +1023,7 @@ mod tests {
fn test_option_cacert_error() {
let mut reader = Reader::init("cacert: ###");
let error = option_cacert(&mut reader).err().unwrap();
assert_eq!(error.recoverable, false)
assert!(!error.recoverable)
}
#[test]

View File

@ -30,7 +30,7 @@ fn debug() {
#[test]
fn test_echo() {
for file in json_files() {
eprintln!("{}", file);
eprintln!("{file}");
let content = read_content(file);
let value = parse_json(content.to_string()).unwrap();
assert_eq!(value.encoded(), content);

View File

@ -51,7 +51,7 @@ pub fn make_logger_linter_error(
}
pub fn log_info(message: &str) {
eprintln!("{}", message);
eprintln!("{message}");
}
fn log_error_message(color: bool, warning: bool, message: &str) {
@ -61,7 +61,7 @@ fn log_error_message(color: bool, warning: bool, message: &str) {
(true, true) => "warning".yellow().bold().to_string(),
(true, false) => "error".red().bold().to_string(),
};
eprintln!("{}: {}", log_type, message);
eprintln!("{log_type}: {message}");
}
fn log_verbose(verbose: bool, message: &str) {
@ -69,7 +69,7 @@ fn log_verbose(verbose: bool, message: &str) {
if message.is_empty() {
eprintln!("*");
} else {
eprintln!("* {}", message);
eprintln!("* {message}");
}
}
}
@ -123,7 +123,7 @@ fn log_error(
line = if line.is_empty() {
line
} else {
format!(" {}", line)
format!(" {line}")
}
);

View File

@ -505,7 +505,7 @@ impl ToJson for JsonValue {
.map(|elem| (elem.name.to_string(), elem.value.to_json()))
.collect(),
),
JsonValue::Expression(exp) => JValue::String(format!("{{{{{}}}}}", exp)),
JsonValue::Expression(exp) => JValue::String(format!("{{{{{exp}}}}}")),
}
}
}

View File

@ -45,7 +45,7 @@ impl JValue {
.map(|e| e.clone().format())
.collect::<Vec<String>>()
.join(",");
format!("[{}]", s)
format!("[{s}]")
}
JValue::Object(key_values) => {
let s = key_values
@ -53,7 +53,7 @@ impl JValue {
.map(|(k, v)| format!("\"{}\":{}", k, v.clone().format()))
.collect::<Vec<String>>()
.join(",");
format!("{{{}}}", s)
format!("{{{s}}}")
}
}
}

View File

@ -713,7 +713,7 @@ impl Tokenizable for Expr {
impl Tokenizable for Regex {
fn tokenize(&self) -> Vec<Token> {
let s = str::replace(self.inner.as_str(), "/", "\\/");
vec![Token::String(format!("/{}/", s))]
vec![Token::String(format!("/{s}/"))]
}
}

View File

@ -145,7 +145,7 @@ fn main() {
println!();
process::exit(1);
} else if filename != "-" && !Path::new(&filename).exists() {
eprintln!("Input file {} does not exit!", filename);
eprintln!("Input file {filename} does not exit!");
process::exit(1);
};
@ -168,7 +168,7 @@ fn main() {
if let Err(e) = io::stdin().read_to_string(&mut contents) {
log_error_message(
false,
format!("Input stream can not be read - {}", e).as_str(),
format!("Input stream can not be read - {e}").as_str(),
);
process::exit(2);
}
@ -233,14 +233,14 @@ fn main() {
let standalone = cli::has_flag(&matches, "standalone");
hurl_core::format::format_html(hurl_file, standalone)
}
"ast" => format!("{:#?}", hurl_file),
"ast" => format!("{hurl_file:#?}"),
_ => {
eprintln!("Invalid output option - expecting text, html or json");
process::exit(1);
}
};
let output = if !output.ends_with('\n') && !cli::has_flag(&matches, "no_format") {
format!("{}\n", output)
format!("{output}\n")
} else {
output
};

View File

@ -254,7 +254,7 @@ fn format_token(token: Token) -> String {
| Token::QueryType(s)
| Token::CodeVariable(s)
| Token::CodeDelimiter(s) => s,
_ => panic!("invalid token {:?}", token),
_ => panic!("invalid token {token:?}"),
}
}
@ -276,7 +276,7 @@ fn test_echo() {
.run(&value(), |value| {
//eprintln!("value={:#?}", value);
let s = format_value(value);
eprintln!("s={}", s);
eprintln!("s={s}");
let mut reader = Reader::init(s.as_str());
let parsed_value = parse_json(&mut reader).unwrap();
assert_eq!(format_value(parsed_value), s);