Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fxpineau committed Mar 11, 2024
1 parent a1095be commit c4d6318
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 33 deletions.
6 changes: 3 additions & 3 deletions crates/cli/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl Input {

pub fn get_fmt(&self) -> Result<InputFormat, VOTableError> {
match &self.input_fmt {
Some(input_fmt) => Ok(input_fmt.clone()),
Some(input_fmt) => Ok(*input_fmt),
None => match &self.input {
Some(path) => InputFormat::from_extension(&path).map_err(VOTableError::Custom),
Some(path) => InputFormat::from_extension(path).map_err(VOTableError::Custom),
None => Err(VOTableError::Custom(String::from(
"Input format **must** be provided when reading from stdin.",
))),
Expand All @@ -102,7 +102,7 @@ impl Input {
let reader = BufReader::new(file);
match self.input_fmt {
Some(input_fmt) => input_fmt.get(reader),
None => InputFormat::from_extension(&path)
None => InputFormat::from_extension(path)
.map_err(VOTableError::Custom)
.and_then(|input_fmt| input_fmt.get(reader)),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pub mod get;
pub mod input;
pub mod output;
pub mod streaming;
pub mod update;
// pub mod update;
pub mod visitors;
6 changes: 3 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use clap::Parser;

use votable::error::VOTableError;
use votable_cli::{convert::Convert, get::Get, streaming::StreamConvert, update::Update};
use votable_cli::{convert::Convert, get::Get, streaming::StreamConvert /*update::Update*/};

#[derive(Debug, Parser)]
#[clap(author, version, about, long_about = None)]
pub enum CliArgs {
Convert(Convert),
Sconvert(StreamConvert),
Update(Update),
// Update(Update),
Get(Get),
}

Expand All @@ -17,7 +17,7 @@ impl CliArgs {
match self {
Self::Convert(p) => p.exec(),
Self::Sconvert(p) => p.exec(),
Self::Update(p) => p.exec(),
// Self::Update(p) => p.exec(),
Self::Get(p) => p.exec(),
}
}
Expand Down
20 changes: 10 additions & 10 deletions crates/cli/src/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ fn td_to_binary2_par<R: BufRead + Send, W: Write>(
.zip(schema.iter())
.map(|(res, schema)| res.and_then(|field_str| schema.value_from_str(&field_str)))
.collect::<Result<Vec<VOTableValue>, VOTableError>>()
.map(|fields| InMemTableDataRows::write_binary2_row(&mut bin_ser, fields, &schema))
.map(|fields| InMemTableDataRows::write_binary2_row(&mut bin_ser, fields, schema))
{
panic!("Error convertings rows: {:?}", e);
}
Expand Down Expand Up @@ -652,8 +652,8 @@ fn binary_to_td_par<R: BufRead + Send, W: Write>(
td_row.append(b"\n<TR>".to_vec().as_mut());
InMemTableDataRows::write_tabledata_row(
&mut new_xml_writer(&mut td_row, None, None),
binrow2fieldit(raw_bin_row, &schema),
&schema,
binrow2fieldit(raw_bin_row, schema),
schema,
)
.unwrap();
td_row.append(b"</TR>".to_vec().as_mut());
Expand Down Expand Up @@ -695,8 +695,8 @@ fn binary_to_binary2_par<R: BufRead + Send, W: Write>(
let mut bin_ser = BinarySerializer::new(&mut bin_row);
if let Err(e) = InMemTableDataRows::write_binary2_row(
&mut bin_ser,
binrow2fieldit(raw_bin_row, &schema).collect::<Vec<VOTableValue>>(),
&schema,
binrow2fieldit(raw_bin_row, schema).collect::<Vec<VOTableValue>>(),
schema,
) {
panic!("Error convertings rows: {:?}", e);
}
Expand Down Expand Up @@ -739,8 +739,8 @@ fn binary2_to_td_par<R: BufRead + Send, W: Write>(
td_row.append(b"\n<TR>".to_vec().as_mut());
InMemTableDataRows::write_tabledata_row(
&mut new_xml_writer(&mut td_row, None, None),
bin2row2fieldit(raw_bin_row, &schema),
&schema,
bin2row2fieldit(raw_bin_row, schema),
schema,
)
.unwrap();
td_row.append(b"</TR>".to_vec().as_mut());
Expand Down Expand Up @@ -786,8 +786,8 @@ fn binary2_to_binary_par<R: BufRead + Send, W: Write>(
let mut bin_ser = BinarySerializer::new(&mut bin_row);
if let Err(e) = InMemTableDataRows::write_binary_row(
&mut bin_ser,
bin2row2fieldit(raw_bin_row, &schema),
&schema,
bin2row2fieldit(raw_bin_row, schema),
schema,
) {
panic!("Error convertings rows: {:?}", e);
}
Expand Down Expand Up @@ -820,7 +820,7 @@ fn write_csv_header<W: Write>(
separator: char,
) -> Result<(), VOTableError> {
// Write header
let mut colname_it = get_colnames(&votable).into_iter();
let mut colname_it = get_colnames(votable).into_iter();
if let Some(colname) = colname_it.next() {
write_1st_csv_field(&mut write, colname.as_str(), separator)?;
for colname in colname_it {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/visitors/fieldarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl FieldAttributesArray {
self.all_fields[FieldElem::Index.index()].push(self.n_rows);
self.all_fields[FieldElem::Id.index()].push_opt(&field.id);
self.all_fields[FieldElem::Name.index()].push(&field.name);
self.all_fields[FieldElem::Datatype.index()].push(&field.datatype);
self.all_fields[FieldElem::Datatype.index()].push(field.datatype);
self.all_fields[FieldElem::Arraysize.index()].push_opt(&field.arraysize);
self.all_fields[FieldElem::Width.index()].push_opt(&field.width);
self.all_fields[FieldElem::Precision.index()].push_opt(&field.precision);
Expand Down
21 changes: 6 additions & 15 deletions crates/cli/src/visitors/votstruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,20 @@ impl<'a> TagPrinter<'a> {
// Add attributes (if any)
self.attrs.reverse(); // to use pop (while preserving input order), hence limit the number of copy
while let Some(mut kv) = self.attrs.pop() {
let mut max_len = self
.line_width
.checked_sub(s.len() + SEP.len())
.unwrap_or(0);
let mut max_len = self.line_width.saturating_sub(s.len() + SEP.len());
if kv.len() <= max_len {
s.push_str(SEP);
s.push_str(kv.as_str());
} else {
// first try to complete with other attributes (size min = 3 because: 'k=v')
while max_len >= 3 && Self::try_append_kv(max_len, &mut s, &mut self.attrs) {
max_len = self
.line_width
.checked_sub(s.len() + SEP.len())
.unwrap_or(0);
max_len = self.line_width.saturating_sub(s.len() + SEP.len());
}
println!("{}", s);
s.clear();
s.push_str(self.indent);
s.push_str(INDENT); // add an extra indent level
max_len = self.line_width.checked_sub(s.len()).unwrap_or(0);
max_len = self.line_width.saturating_sub(s.len());
if kv.len() <= max_len {
s.push_str(kv.as_str());
} else {
Expand All @@ -118,7 +112,7 @@ impl<'a> TagPrinter<'a> {
if let Some(content) = self.content {
let mut content_clean = String::with_capacity(content.len() + 8);
content_clean.push_str("content=");
let content = content.trim().replace(&['\n'], "\\n");
let content = content.trim().replace(['\n'], "\\n");
let mut word_it = content.split_whitespace();
if let Some(word) = word_it.next() {
content_clean.push_str(word);
Expand All @@ -128,10 +122,7 @@ impl<'a> TagPrinter<'a> {
}
}
let mut content = content_clean;
let mut max_len = self
.line_width
.checked_sub(s.len() + SEP.len())
.unwrap_or(0);
let mut max_len = self.line_width.saturating_sub(s.len() + SEP.len());
if content.len() <= max_len {
// Print on the same line, no need to truncate
s.push_str(SEP);
Expand All @@ -148,7 +139,7 @@ impl<'a> TagPrinter<'a> {
s.clear();
s.push_str(self.indent);
s.push_str(INDENT); // add an extra indent level
max_len = self.line_width.checked_sub(s.len()).unwrap_or(0);
max_len = self.line_width.saturating_sub(s.len());
if content.len() <= max_len {
// Not truncation needed
s.push_str(content.as_str());
Expand Down

0 comments on commit c4d6318

Please sign in to comment.