namib-project / libcoap-rs

Rust bindings to and wrapper around the libcoap C library
BSD 2-Clause "Simplified" License
7 stars 1 forks source link

feat: improve URI handling by basing it on the libcoap type #18

Closed pulsastrix closed 3 months ago

pulsastrix commented 3 months ago

This PR rewrites the CoapUri type to work directly with an underlying coap_uri_t object and use the libcoap-provided uri parsing functions.

Additionally the url crate is now an optional dependency, and the CoapUri type now implements FromStr, which allows way easier construction of URIs.

Before (using url crate):

let uri = CoapUri::try_from_url(Url::parse("coap://example.com:4711/foo/bar?answer=42")?)?;

Before (without url crate):

let uri = CoapUri::new(
        CoapUriScheme::Coap,
        Some(CoapUriHost::Name("example.com".to_string())),
        Some(4711),
        Some(vec!["foo".to_string(), "bar".to_string()]),
        Some(vec!["answer=42".to_string()]),,
    );

Now:

let uri: CoapUri = "coap://example.com:4711/foo/bar?answer=42".parse()?;
github-actions[bot] commented 3 months ago

Code Coverage Report

Generated for commit 44d605d6605e69f597d1b766d2ddfc0d4ca58cda on Thu Jul 18 15:34:28 UTC 2024. Code Coverage

Package Line Rate Health
libcoap/tests/common 88%
libcoap/src/message 37%
libcoap/src/session 53%
libcoap/tests 91%
libcoap-sys 70%
libcoap-sys/src 70%
libcoap/src 44%
Summary 46% (894 / 1946)
pulsastrix commented 3 months ago

Apparently there seems to be some issue with doctests and the unstable --ensure-time cargo flag.

For now, I have disabled these unstable flags and changed the toolchain the tests are run on to stable Rust.