Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Implement 'to_vec' and 'from_slice' for no_std #147

Merged
merged 1 commit into from
Sep 8, 2019

Conversation

geigerzaehler
Copy link
Contributor

@geigerzaehler geigerzaehler commented Sep 2, 2019

We implement serde_cbor::to_vec() and serde_cbor::from_slice() in a no_std environment to simplify serialization. For this we use alloc::vec::Vec.

@geigerzaehler geigerzaehler changed the title Implement 'to_vec' for no_std Implement 'to_vec' and 'from_slice' for no_std Sep 2, 2019
@geigerzaehler
Copy link
Contributor Author

Unfortunately this does not build with Rust 1.31.0 because the alloc crate is not available. I’d suggest not running the --no-default-features tests on Rust 1.31.0 and documenting that this only works with newer versions of Rust. Alternatively we could introduce an alloc flag (like serde) so that no_std still works with Rust 1.31.0.

@geigerzaehler geigerzaehler marked this pull request as ready for review September 2, 2019 11:04
@pyfisch
Copy link
Owner

pyfisch commented Sep 2, 2019

Is it correct that with this change alloc is always used?
I think there are people using CBOR on systems which do not support allocation.

@geigerzaehler
Copy link
Contributor Author

Is it correct that with this change alloc is always used?

I think so, though I’m not super familiar with alloc to be honest.

I think there are people using CBOR on systems which do not support allocation.

Ok. It might be best then to put this behind a feature flag. This also aligns with serde and retains compatibility with 1.31.0. I’ll update the PR accordingly.

@geigerzaehler geigerzaehler force-pushed the to-vec-no-std branch 2 times, most recently from 2fd5c95 to 6f7020a Compare September 3, 2019 08:42
@pyfisch
Copy link
Owner

pyfisch commented Sep 7, 2019

cc @wildarch @chrysn

Copy link
Contributor

@wildarch wildarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just left one tiny nit in the interest of concise documentation, feel free to leave as is if you disagree.

LGTM! 😄

src/de.rs Outdated Show resolved Hide resolved
We implement `to_vec()` and `from_slice()` in a `no_std` environment to
simplify serialization. For this we require the `alloc` feature flag.
@pyfisch pyfisch merged commit d769647 into pyfisch:master Sep 8, 2019
@geigerzaehler geigerzaehler deleted the to-vec-no-std branch September 8, 2019 18:44
@geigerzaehler geigerzaehler restored the to-vec-no-std branch September 9, 2019 06:17
martindisch added a commit to martindisch/oscore that referenced this pull request Sep 14, 2019
@pyfisch
Copy link
Owner

pyfisch commented Oct 5, 2019

@geigerzaehler By the way this PR broke Travis CI. 😉 See: #154 and https://stackoverflow.com/questions/58249675/travis-ci-fails-to-parse-travis-yml

@geigerzaehler
Copy link
Contributor Author

Sorry and thanks for fixing. I was wondering where the green checkmark was. To bad Travis does not fail the build when it can’t parse .travis.yaml.

pyfisch added a commit that referenced this pull request Oct 10, 2019
Update .travis.yml to include tests if the crate builds with the `alloc` feature enabled.
These scripts are only executed if the rust version is != 1.31.0.
These changes were originally included in #147 but with incorrect YAML syntax.
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants