feat: improve URI handling by basing it on the libcoap type #112
reviewdog [clippy (libcoap-rs)] report
reported by reviewdog 🐶
Findings (7)
libcoap/src/message/request.rs|391 col 41| warning: use of format!
to build up a string from an iterator
--> libcoap/src/message/request.rs:391:41
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: call fold
instead
--> libcoap/src/message/request.rs:391:50
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::());
| ^^^
help: ... and use the write!
macro here
--> libcoap/src/message/request.rs:391:58
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::());
| ^^^^^^^^^^^^^^^^^
= note: this can be written more efficiently by appending to a String
directly
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_collect
= note: #[warn(clippy::format_collect)]
on by default
libcoap/src/message/request.rs|399 col 21| warning: manual implementation of an assign operation
--> libcoap/src/message/request.rs:399:21
|
399 | out_str = out_str + format!("&{}", q).as_ref();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: out_str += format!("&{}", q).as_ref()
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
= note: #[warn(clippy::assign_op_pattern)]
on by default
libcoap/src/message/request.rs|407 col 21| warning: called .as_ref().map(|v| v.as_slice())
on an Option
value
--> libcoap/src/message/request.rs:407:21
|
407 | host.as_ref().map(|v| v.as_slice()).unwrap_or(&[]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: host.as_deref()
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
= note: #[warn(clippy::option_as_ref_deref)]
on by default
libcoap/src/message/request.rs|414 col 21| warning: called .as_ref().map(|v| v.as_slice())
on an Option
value
--> libcoap/src/message/request.rs:414:21
|
414 | host.as_ref().map(|v| v.as_slice()).unwrap_or(&[]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: host.as_deref()
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
libcoap/src/message/response.rs|327 col 50| warning: use of format!
to build up a string from an iterator
--> libcoap/src/message/response.rs:327:50
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: call fold
instead
--> libcoap/src/message/response.rs:327:59
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::());
| ^^^
help: ... and use the write!
macro here
--> libcoap/src/message/response.rs:327:67
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::());
| ^^^^^^^^^^^^^^^^^
= note: this can be written more efficiently by appending to a String
directly
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_collect
libcoap/src/types.rs|539 col 9| warning: this block may be rewritten with the ?
operator
--> libcoap/src/types.rs:539:9
|
539 | / if self.host().is_none() {
540 | | return None;
541 | | }
| |_________^ help: replace it with: self.host()?;
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
= note: #[warn(clippy::question_mark)]
on by default
libcoap/src/types.rs|742 col 25| warning: length comparison to zero
--> libcoap/src/types.rs:742:25
|
742 | let scheme = if host.len() != 0 {
| ^^^^^^^^^^^^^^^ help: using !is_empty
is clearer and more explicit: !host.is_empty()
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
= note: #[warn(clippy::len_zero)]
on by default
Filtered Findings (9)
libcoap-sys/build.rs|97 col 5| warning: unnecessary unsafe
block
--> libcoap-sys/build.rs:97:5
|
97 | unsafe { env::set_var("PATH", embuild_env) };
| ^^^^^^ unnecessary unsafe
block
|
= note: #[warn(unused_unsafe)]
on by default
libcoap/src/context.rs|601 col 11| warning: unneeded sub cfg
when there is only one condition
--> libcoap/src/context.rs:601:11
|
601 | #[cfg(all(feature = "dtls"))]
| ^^^^^^^^^^^^^^^^^^^^^ help: try: feature = "dtls"
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_minimal_cfg
= note: #[warn(clippy::non_minimal_cfg)]
on by default
libcoap/src/session/mod.rs|47 col 1| warning: unnecessary pub(self)
--> libcoap/src/session/mod.rs:47:1
|
47 | pub(self) use self::sealed::{CoapSessionCommonInternal, CoapSessionInnerProvider};
| ^^^^^^^^^ help: remove it
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pub_self
= note: #[warn(clippy::needless_pub_self)]
on by default
libcoap/src/resource.rs|103 col 11| warning: methods uri_path
and as_any
are never used
--> libcoap/src/resource.rs:105:8
|
103 | pub trait UntypedCoapResource: Any + Debug {
| ------------------- methods in this trait
104 | /// Returns the uri_path this resource responds to.
105 | fn uri_path(&self) -> &str;
| ^^^^^^^^
...
112 | fn as_any(&self) -> &dyn Any;
| ^^^^^^
|
= note: #[warn(dead_code)]
on by default
libcoap/src/context.rs|119 col 17| warning: useless conversion to the same type: u32
--> libcoap/src/context.rs:119:17
|
119 | / (COAP_BLOCK_USE_LIBCOAP | COAP_BLOCK_SINGLE_BODY)
120 | | .try_into()
| |_______________________________^
|
= help: consider removing .try_into()
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
= note: #[warn(clippy::useless_conversion)]
on by default
libcoap/src/crypto.rs|145 col 18| warning: casting raw pointers to the same type and constness is unnecessary (*const libcoap_sys::coap_dtls_cpsk_info_t
-> *const libcoap_sys::coap_dtls_cpsk_info_t
)
--> libcoap/src/crypto.rs:145:18
|
145 | .map(|v| v as *const coap_dtls_cpsk_info_t)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: v
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
= note: #[warn(clippy::unnecessary_cast)]
on by default
libcoap/src/crypto.rs|173 col 22| warning: casting raw pointers to the same type and constness is unnecessary (*const libcoap_sys::coap_dtls_spsk_info_t
-> *const libcoap_sys::coap_dtls_spsk_info_t
)
--> libcoap/src/crypto.rs:173:22
|
173 | .map(|v| (v as *const coap_dtls_spsk_info_t))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: v
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
libcoap/src/session/client.rs|140 col 17| warning: casting raw pointers to the same type and constness is unnecessary (*mut libcoap_sys::coap_session_t
-> *mut libcoap_sys::coap_session_t
)
--> libcoap/src/session/client.rs:140:17
|
140 | session as *mut coap_session_t,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: session
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
libcoap/src/session/client.rs|174 col 17| warning: casting raw pointers to the same type and constness is unnecessary (*mut libcoap_sys::coap_session_t
-> *mut libcoap_sys::coap_session_t
)
--> libcoap/src/session/client.rs:174:17
|
174 | session as *mut coap_session_t,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: session
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
Annotations
Check warning on line 391 in libcoap/src/message/request.rs
github-actions / clippy (libcoap-rs)
[clippy (libcoap-rs)] libcoap/src/message/request.rs#L391
warning: use of `format!` to build up a string from an iterator
--> libcoap/src/message/request.rs:391:41
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: call `fold` instead
--> libcoap/src/message/request.rs:391:50
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^
help: ... and use the `write!` macro here
--> libcoap/src/message/request.rs:391:58
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^^^^^^^^^^^^^^^
= note: this can be written more efficiently by appending to a `String` directly
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_collect
= note: `#[warn(clippy::format_collect)]` on by default
Raw output
libcoap/src/message/request.rs:391:41:w:warning: use of `format!` to build up a string from an iterator
--> libcoap/src/message/request.rs:391:41
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: call `fold` instead
--> libcoap/src/message/request.rs:391:50
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^
help: ... and use the `write!` macro here
--> libcoap/src/message/request.rs:391:58
|
391 | let path_str = path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^^^^^^^^^^^^^^^
= note: this can be written more efficiently by appending to a `String` directly
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_collect
= note: `#[warn(clippy::format_collect)]` on by default
__END__
Check warning on line 399 in libcoap/src/message/request.rs
github-actions / clippy (libcoap-rs)
[clippy (libcoap-rs)] libcoap/src/message/request.rs#L399
warning: manual implementation of an assign operation
--> libcoap/src/message/request.rs:399:21
|
399 | out_str = out_str + format!("&{}", q).as_ref();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `out_str += format!("&{}", q).as_ref()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
= note: `#[warn(clippy::assign_op_pattern)]` on by default
Raw output
libcoap/src/message/request.rs:399:21:w:warning: manual implementation of an assign operation
--> libcoap/src/message/request.rs:399:21
|
399 | out_str = out_str + format!("&{}", q).as_ref();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `out_str += format!("&{}", q).as_ref()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
= note: `#[warn(clippy::assign_op_pattern)]` on by default
__END__
Check warning on line 407 in libcoap/src/message/request.rs
github-actions / clippy (libcoap-rs)
[clippy (libcoap-rs)] libcoap/src/message/request.rs#L407
warning: called `.as_ref().map(|v| v.as_slice())` on an `Option` value
--> libcoap/src/message/request.rs:407:21
|
407 | host.as_ref().map(|v| v.as_slice()).unwrap_or(&[]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `host.as_deref()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
= note: `#[warn(clippy::option_as_ref_deref)]` on by default
Raw output
libcoap/src/message/request.rs:407:21:w:warning: called `.as_ref().map(|v| v.as_slice())` on an `Option` value
--> libcoap/src/message/request.rs:407:21
|
407 | host.as_ref().map(|v| v.as_slice()).unwrap_or(&[]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `host.as_deref()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
= note: `#[warn(clippy::option_as_ref_deref)]` on by default
__END__
Check warning on line 414 in libcoap/src/message/request.rs
github-actions / clippy (libcoap-rs)
[clippy (libcoap-rs)] libcoap/src/message/request.rs#L414
warning: called `.as_ref().map(|v| v.as_slice())` on an `Option` value
--> libcoap/src/message/request.rs:414:21
|
414 | host.as_ref().map(|v| v.as_slice()).unwrap_or(&[]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `host.as_deref()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
Raw output
libcoap/src/message/request.rs:414:21:w:warning: called `.as_ref().map(|v| v.as_slice())` on an `Option` value
--> libcoap/src/message/request.rs:414:21
|
414 | host.as_ref().map(|v| v.as_slice()).unwrap_or(&[]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `host.as_deref()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
__END__
Check warning on line 327 in libcoap/src/message/response.rs
github-actions / clippy (libcoap-rs)
[clippy (libcoap-rs)] libcoap/src/message/response.rs#L327
warning: use of `format!` to build up a string from an iterator
--> libcoap/src/message/response.rs:327:50
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: call `fold` instead
--> libcoap/src/message/response.rs:327:59
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^
help: ... and use the `write!` macro here
--> libcoap/src/message/response.rs:327:67
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^^^^^^^^^^^^^^^
= note: this can be written more efficiently by appending to a `String` directly
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_collect
Raw output
libcoap/src/message/response.rs:327:50:w:warning: use of `format!` to build up a string from an iterator
--> libcoap/src/message/response.rs:327:50
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: call `fold` instead
--> libcoap/src/message/response.rs:327:59
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^
help: ... and use the `write!` macro here
--> libcoap/src/message/response.rs:327:67
|
327 | let path_str = location_path.map(|v| v.iter().map(|v| format!("/{}", v)).collect::<String>());
| ^^^^^^^^^^^^^^^^^
= note: this can be written more efficiently by appending to a `String` directly
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_collect
__END__
Check warning on line 539 in libcoap/src/types.rs
github-actions / clippy (libcoap-rs)
[clippy (libcoap-rs)] libcoap/src/types.rs#L539
warning: this block may be rewritten with the `?` operator
--> libcoap/src/types.rs:539:9
|
539 | / if self.host().is_none() {
540 | | return None;
541 | | }
| |_________^ help: replace it with: `self.host()?;`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
= note: `#[warn(clippy::question_mark)]` on by default
Raw output
libcoap/src/types.rs:539:9:w:warning: this block may be rewritten with the `?` operator
--> libcoap/src/types.rs:539:9
|
539 | / if self.host().is_none() {
540 | | return None;
541 | | }
| |_________^ help: replace it with: `self.host()?;`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
= note: `#[warn(clippy::question_mark)]` on by default
__END__
Check warning on line 742 in libcoap/src/types.rs
github-actions / clippy (libcoap-rs)
[clippy (libcoap-rs)] libcoap/src/types.rs#L742
warning: length comparison to zero
--> libcoap/src/types.rs:742:25
|
742 | let scheme = if host.len() != 0 {
| ^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!host.is_empty()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
= note: `#[warn(clippy::len_zero)]` on by default
Raw output
libcoap/src/types.rs:742:25:w:warning: length comparison to zero
--> libcoap/src/types.rs:742:25
|
742 | let scheme = if host.len() != 0 {
| ^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!host.is_empty()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
= note: `#[warn(clippy::len_zero)]` on by default
__END__