Skip to content

Commit

Permalink
Fix clippy warnings about unnecessary .clone(), .into(), borrowin…
Browse files Browse the repository at this point in the history
…g and let statement
  • Loading branch information
haixuanTao committed Aug 29, 2023
1 parent 9805d06 commit 90c28de
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion binaries/cli/src/template/c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn create_dataflow(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrR

let dataflow_yml = DATAFLOW_YML.replace("___name___", &name);
let dataflow_yml_path = root.join("dataflow.yml");
fs::write(&dataflow_yml_path, &dataflow_yml)
fs::write(&dataflow_yml_path, dataflow_yml)
.with_context(|| format!("failed to write `{}`", dataflow_yml_path.display()))?;

create_operator("op_1".into(), Some(root.join("op_1")))?;
Expand Down
2 changes: 1 addition & 1 deletion binaries/cli/src/template/cxx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn create_dataflow(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrR

let dataflow_yml = DATAFLOW_YML.replace("___name___", &name);
let dataflow_yml_path = root.join("dataflow.yml");
fs::write(&dataflow_yml_path, &dataflow_yml)
fs::write(&dataflow_yml_path, dataflow_yml)
.with_context(|| format!("failed to write `{}`", dataflow_yml_path.display()))?;

create_operator("op_1".into(), Some(root.join("op_1")))?;
Expand Down
2 changes: 1 addition & 1 deletion binaries/cli/src/template/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn create_dataflow(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrR

let dataflow_yml = DATAFLOW_YML.replace("___name___", &name);
let dataflow_yml_path = root.join("dataflow.yml");
fs::write(&dataflow_yml_path, &dataflow_yml)
fs::write(&dataflow_yml_path, dataflow_yml)
.with_context(|| format!("failed to write `{}`", dataflow_yml_path.display()))?;

create_operator("op_1".into(), Some(root.join("op_1")))?;
Expand Down
8 changes: 4 additions & 4 deletions binaries/cli/src/template/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ fn create_dataflow(

let dataflow_yml = DATAFLOW_YML.replace("___name___", &name);
let dataflow_yml_path = root.join("dataflow.yml");
fs::write(&dataflow_yml_path, &dataflow_yml)
fs::write(&dataflow_yml_path, dataflow_yml)
.with_context(|| format!("failed to write `{}`", dataflow_yml_path.display()))?;
let cargo_toml = WORKSPACE_CARGO_TOML.replace("___name___", &name);
let cargo_toml_path = root.join("Cargo.toml");
fs::write(&cargo_toml_path, &cargo_toml)
fs::write(&cargo_toml_path, cargo_toml)
.with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?;

create_operator("op_1".into(), Some(root.join("op_1")), use_path_deps)?;
Expand Down Expand Up @@ -100,7 +100,7 @@ fn create_operator(
.replace("dora-operator-api = {}", &dep);

let cargo_toml_path = root.join("Cargo.toml");
fs::write(&cargo_toml_path, &cargo_toml)
fs::write(&cargo_toml_path, cargo_toml)
.with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?;

let lib_rs_path = src.join("lib.rs");
Expand Down Expand Up @@ -147,7 +147,7 @@ fn create_custom_node(
.replace("___name___", &name)
.replace("dora-node-api = {}", &dep);
let cargo_toml_path = root.join("Cargo.toml");
fs::write(&cargo_toml_path, &cargo_toml)
fs::write(&cargo_toml_path, cargo_toml)
.with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?;

let main_rs_path = src.join("main.rs");
Expand Down
2 changes: 1 addition & 1 deletion binaries/daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ impl RunningDataflow {
watermark: 0,
deadline: 0,
#[cfg(feature = "telemetry")]
open_telemetry_context: serialize_context(&span.context()).into(),
open_telemetry_context: serialize_context(&span.context()),
#[cfg(not(feature = "telemetry"))]
open_telemetry_context: "".into(),
},
Expand Down
6 changes: 2 additions & 4 deletions binaries/runtime/src/operator/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,9 @@ mod callback_impl {
sample: tx,
})
.map_err(|_| eyre!("failed to send output to runtime"))?;
let sample = rx
.blocking_recv()
rx.blocking_recv()
.wrap_err("failed to request output sample")?
.wrap_err("failed to allocate output sample")?;
sample
.wrap_err("failed to allocate output sample")?
} else {
vec![0; data_len].into()
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/extensions/ros2-bridge/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use dora_ros2_bridge_msg_gen::types::Message;
use eyre::{eyre, Context, ContextCompat};
use futures::{Stream, StreamExt};
use pyo3::{
prelude::{pyclass, pymethods, pymodule},
prelude::{pyclass, pymethods},
types::PyModule,
PyAny, PyObject, PyResult, Python,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ impl<'de> serde::de::Visitor<'de> for ListVisitor {
if let Ok(values) = data {
let offsets = OffsetBuffer::new(vec![0, values.len() as i32].into());

let array =
ListArray::new(self.field, offsets.clone(), make_array(values), None).to_data();
let array = ListArray::new(self.field, offsets, make_array(values), None).to_data();
Ok(array)
} else {
Ok(self.defaults) // TODO: Better handle deserialization error
Expand Down
40 changes: 17 additions & 23 deletions libraries/extensions/ros2-bridge/python/src/typed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn default_for_member(
.as_deref()
{
Some([]) => eyre::bail!("empty default value not supported"),
Some([default]) => preset_default_for_basic_type(t, &default)
Some([default]) => preset_default_for_basic_type(t, default)
.with_context(|| format!("failed to parse default value for `{}`", m.name))?,
Some(_) => eyre::bail!(
"there should be only a single default value for non-sequence types"
Expand Down Expand Up @@ -237,9 +237,9 @@ fn list_default_values(
let raw_array: Vec<Arc<dyn Array>> = defaults
.iter()
.map(|default| {
preset_default_for_basic_type(value_type, &default)
preset_default_for_basic_type(value_type, default)
.with_context(|| format!("failed to parse default value for `{}`", m.name))
.map(|data| make_array(data))
.map(make_array)
})
.collect::<Result<_, _>>()?;
let default_values = concat(
Expand All @@ -254,28 +254,22 @@ fn list_default_values(
}
None => {
let default_nested_type =
default_for_nestable_type(&value_type, package_name, messages)?;
if false {
//let NestableType::BasicType(_t) = seq.value_type {
default_nested_type.into()
} else {
let value_offsets = Buffer::from_slice_ref([0i64, 1]);
default_for_nestable_type(value_type, package_name, messages)?;

let list_data_type = DataType::List(Arc::new(Field::new(
&m.name,
default_nested_type.data_type().clone(),
true,
)));
// Construct a list array from the above two
let array = ArrayData::builder(list_data_type)
.len(1)
.add_buffer(value_offsets.clone())
.add_child_data(default_nested_type.clone())
.build()
.unwrap();
let value_offsets = Buffer::from_slice_ref([0i64, 1]);

array.into()
}
let list_data_type = DataType::List(Arc::new(Field::new(
&m.name,
default_nested_type.data_type().clone(),
true,
)));
// Construct a list array from the above two
ArrayData::builder(list_data_type)
.len(1)
.add_buffer(value_offsets)
.add_child_data(default_nested_type)
.build()
.context("Failed to build default list value")?
}
};

Expand Down
10 changes: 5 additions & 5 deletions libraries/extensions/ros2-bridge/python/src/typed/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl serde::Serialize for TypedValue<'_> {
let value = match value {
Some(value) => value.to_data(),
None => {
return Err(serde::ser::Error::custom(format!(
"Value in ListArray is null and not yet supported",
)))
return Err(serde::ser::Error::custom(
"Value in ListArray is null and not yet supported".to_string(),
))
}
};

Expand All @@ -110,7 +110,7 @@ impl serde::Serialize for TypedValue<'_> {
}
s.end()
} else {
return Err(serde::ser::Error::custom(format!("Wrong fields type",)));
Err(serde::ser::Error::custom("Wrong fields type".to_string()))
}
}
DataType::Struct(_fields) => {
Expand Down Expand Up @@ -157,7 +157,7 @@ impl serde::Serialize for TypedValue<'_> {
}
s.end()
} else {
return Err(serde::ser::Error::custom(format!("Wrong fields type",)));
Err(serde::ser::Error::custom("Wrong fields type".to_string()))
}
}
_ => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion libraries/message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct MetadataParameters {
impl MetadataParameters {
pub fn into_owned(self) -> MetadataParameters {
MetadataParameters {
open_telemetry_context: self.open_telemetry_context.into(),
open_telemetry_context: self.open_telemetry_context,
..self
}
}
Expand Down

0 comments on commit 90c28de

Please sign in to comment.