Skip to content

Commit

Permalink
use into rather than to_string for fn args
Browse files Browse the repository at this point in the history
  • Loading branch information
warthog618 committed Feb 18, 2024
1 parent afb5182 commit 874299c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions lib/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Request {
.offsets
.iter()
.position(|v| v == &offset)
.ok_or_else(|| Error::InvalidArgument("offset is not a requested line.".to_string()))?;
.ok_or_else(|| Error::InvalidArgument("offset is not a requested line.".into()))?;
self.do_value(idx)
}
#[cfg(all(feature = "uapi_v1", feature = "uapi_v2"))]
Expand Down Expand Up @@ -285,7 +285,7 @@ impl Request {
if !values.contains_keys(&self.offsets) {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"requires all requested lines".to_string(),
"requires all requested lines".into(),
));
}
v1::set_line_values(&self.f, &values.to_v1(&self.offsets))
Expand All @@ -296,7 +296,7 @@ impl Request {
let lv = &values.to_v2(&self.offsets);
if lv.mask == 0 {
return Err(Error::InvalidArgument(
"no requested lines in set values.".to_string(),
"no requested lines in set values.".into(),
));
}
v2::set_line_values(&self.f, lv).map_err(|e| Error::Uapi(UapiCall::SetLineValues, e))
Expand All @@ -322,7 +322,7 @@ impl Request {
.offsets
.iter()
.position(|v| v == &offset)
.ok_or_else(|| Error::InvalidArgument("offset is not a requested line.".to_string()))?;
.ok_or_else(|| Error::InvalidArgument("offset is not a requested line.".into()))?;
self.do_set_value(idx, value)
}
#[cfg(all(feature = "uapi_v1", feature = "uapi_v2"))]
Expand All @@ -345,7 +345,7 @@ impl Request {
if self.offsets.len() > 1 {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"requires all requested lines".to_string(),
"requires all requested lines".into(),
));
}
let mut vals = v1::LineValues::default();
Expand Down Expand Up @@ -426,13 +426,13 @@ impl Request {
{
return Err(Error::AbiLimitation(
AbiVersion::V1,
"cannot reconfigure lines with edge detection".to_string(),
"cannot reconfigure lines with edge detection".into(),
));
}
if cfg.unique()?.edge_detection.is_some() {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"cannot reconfigure edge detection".to_string(),
"cannot reconfigure edge detection".into(),
));
}
v1::set_line_config(&self.f, cfg.to_v1()?)
Expand All @@ -454,13 +454,13 @@ impl Request {
{
return Err(Error::AbiLimitation(
AbiVersion::V1,
"cannot reconfigure lines with edge detection".to_string(),
"cannot reconfigure lines with edge detection".into(),
));
}
if cfg.unique()?.edge_detection.is_some() {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"cannot reconfigure edge detection".to_string(),
"cannot reconfigure edge detection".into(),
));
}
v1::set_line_config(&self.f, cfg.to_v1()?)
Expand Down
14 changes: 7 additions & 7 deletions lib/src/request/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Builder {
return Err(e.clone());
}
if self.cfg.chip.as_os_str().is_empty() {
return Err(Error::InvalidArgument("No chip specified.".to_string()));
return Err(Error::InvalidArgument("No chip specified.".into()));
}
let chip = Chip::from_path(&self.cfg.chip)?;
self.cfg.offsets.sort_unstable();
Expand Down Expand Up @@ -274,7 +274,7 @@ impl Builder {
self.cfg.on_chip(path);
} else if self.cfg.chip != path.into() {
self.err = Some(Error::InvalidArgument(
"Multiple chips requested.".to_string(),
"Multiple chips requested.".into(),
))
}
self
Expand Down Expand Up @@ -482,7 +482,7 @@ impl Builder {
// Conversions into uAPI types.
fn to_uapi(&self) -> Result<UapiRequest> {
if self.cfg.num_lines() == 0 {
return Err(Error::InvalidArgument("No lines specified.".to_string()));
return Err(Error::InvalidArgument("No lines specified.".into()));
}
if self.cfg.offsets.len() > NUM_LINES_MAX {
return Err(Error::InvalidArgument(format!(
Expand Down Expand Up @@ -514,20 +514,20 @@ impl Builder {
if self.kernel_event_buffer_size != 0 {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"does not support setting event buffer size".to_string(),
"does not support setting event buffer size".into(),
));
}
let lcfg = self.cfg.unique()?;
if lcfg.debounce_period.is_some() {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"does not support debounce".to_string(),
"does not support debounce".into(),
));
}
if lcfg.event_clock.is_some() {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"does not support selecting the event clock source".to_string(),
"does not support selecting the event clock source".into(),
));
}
let consumer = if self.consumer.is_empty() {
Expand All @@ -539,7 +539,7 @@ impl Builder {
if self.cfg.offsets.len() != 1 {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"only supports edge detection on single line requests".to_string(),
"only supports edge detection on single line requests".into(),
));
}
Ok(UapiRequest::Event(v1::EventRequest {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/request/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Config {
Ok(self)
} else {
Err(Error::InvalidArgument(
"Multiple chips requested.".to_string(),
"Multiple chips requested.".into(),
))
}
}
Expand Down Expand Up @@ -403,7 +403,7 @@ impl Config {
if !lcfg.equivalent(self.lcfg.get(offset).unwrap()) {
return Err(Error::AbiLimitation(
AbiVersion::V1,
"requires all lines to share the same configuration".to_string(),
"requires all lines to share the same configuration".into(),
));
}
}
Expand Down
22 changes: 11 additions & 11 deletions lib/tests/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod builder {
.request();
assert_eq!(
res.unwrap_err(),
gpiocdev::Error::AbiLimitation(V1, "does not support debounce".to_string(),)
gpiocdev::Error::AbiLimitation(V1, "does not support debounce".into(),)
);
}

Expand All @@ -93,7 +93,7 @@ mod builder {
res.unwrap_err(),
gpiocdev::Error::AbiLimitation(
V1,
"does not support selecting the event clock source".to_string(),
"does not support selecting the event clock source".into(),
)
);
}
Expand All @@ -117,7 +117,7 @@ mod builder {
res.unwrap_err(),
gpiocdev::Error::AbiLimitation(
V1,
"does not support setting event buffer size".to_string(),
"does not support setting event buffer size".into(),
)
);
}
Expand Down Expand Up @@ -680,7 +680,7 @@ mod builder {
.as_input()
.request()
.unwrap_err(),
gpiocdev::Error::InvalidArgument("Multiple chips requested.".to_string())
gpiocdev::Error::InvalidArgument("Multiple chips requested.".into())
);
}

Expand Down Expand Up @@ -828,7 +828,7 @@ mod builder {
.request();
assert_eq!(
res.unwrap_err(),
gpiocdev::Error::InvalidArgument("Multiple chips requested.".to_string())
gpiocdev::Error::InvalidArgument("Multiple chips requested.".into())
);
}

Expand Down Expand Up @@ -1285,7 +1285,7 @@ mod request {
let res = req.value(3);
assert_eq!(
res.unwrap_err(),
gpiocdev::Error::InvalidArgument("offset is not a requested line.".to_string())
gpiocdev::Error::InvalidArgument("offset is not a requested line.".into())
);
}

Expand Down Expand Up @@ -1415,7 +1415,7 @@ mod request {
req.set_value(*offset, Value::Active).unwrap_err(),
gpiocdev::Error::AbiLimitation(
AbiVersion::V1,
"requires all requested lines".to_string(),
"requires all requested lines".into(),
)
);
}
Expand All @@ -1425,7 +1425,7 @@ mod request {
let res = req.set_value(3, Value::Active);
assert_eq!(
res.unwrap_err(),
gpiocdev::Error::InvalidArgument("offset is not a requested line.".to_string())
gpiocdev::Error::InvalidArgument("offset is not a requested line.".into())
);
}

Expand Down Expand Up @@ -1501,7 +1501,7 @@ mod request {
req.set_values(&vals).unwrap_err(),
gpiocdev::Error::AbiLimitation(
AbiVersion::V1,
"requires all requested lines".to_string(),
"requires all requested lines".into(),
)
);

Expand All @@ -1512,7 +1512,7 @@ mod request {
req.set_values(&vals).unwrap_err(),
gpiocdev::Error::AbiLimitation(
AbiVersion::V1,
"requires all requested lines".to_string(),
"requires all requested lines".into(),
)
);

Expand All @@ -1522,7 +1522,7 @@ mod request {
req.set_values(&vals),
Err(gpiocdev::Error::AbiLimitation(
AbiVersion::V1,
"requires all requested lines".to_string()
"requires all requested lines".into()
))
);
}
Expand Down

0 comments on commit 874299c

Please sign in to comment.