Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify alloc/std imports #391

Closed
FelixMcFelix opened this issue Sep 8, 2023 · 0 comments · Fixed by #400
Closed

Simplify alloc/std imports #391

FelixMcFelix opened this issue Sep 8, 2023 · 0 comments · Fixed by #400
Labels
cleanup Code cleanliness

Comments

@FelixMcFelix
Copy link
Collaborator

Most files throughout OPTE have some form of the following import block:

cfg_if! {
    if #[cfg(all(not(feature = "std"), not(test)))] {
        use alloc::string::String;
        use alloc::string::ToString;
        use alloc::vec::Vec;
    } else {
        use std::string::String;
        use std::string::ToString;
        use std::vec::Vec;
    }
}

This is redundant, as these are re-exported identical types. This current construction stems from all our crates conditionally importing alloc or std – only std should be conditional. We should likely be doing the following:

Before After
#![no_std]

#[cfg(any(feature = "std", test))]
#[macro_use]
extern crate std;

#[cfg(all(not(feature = "std"), not(test)))]
#[macro_use]
extern crate alloc;
#![no_std]

#[cfg(any(feature = "std", test))]
#[macro_use]
extern crate std;

#[macro_use]
extern crate alloc;
cfg_if! {
    if #[cfg(all(not(feature = "std"), not(test)))] {
        use alloc::string::String;
        use alloc::string::ToString;
        use alloc::vec::Vec;
    } else {
        use std::string::String;
        use std::string::ToString;
        use std::vec::Vec;
    }
}
use alloc::string::String;
use alloc::string::ToString;
use alloc::vec::Vec;
@FelixMcFelix FelixMcFelix added the cleanup Code cleanliness label Sep 8, 2023
FelixMcFelix added a commit that referenced this issue Oct 24, 2023
FelixMcFelix added a commit that referenced this issue Oct 26, 2023
* Chore: Update toolchains, dependencies

This simply updates to the latest stable/nightly Rust toolchains, and
runs `cargo update` to pull in the latest version of related
dependencies -- at least one of the locked dependencies was broken on
newer nightlies.

* Rerun Cargo-fmt

* Chore: bump pcap-parser version

Pcap-parser was holding back a shared memchr version. Other dependencies
will follow as appropriate.

* Chore: Simplify duplicate alloc/std imports

Closes #391.

* Bump API_VERSION, move MAJOR_VERSION to api

* Chore: Bump most dependencies

This excludes smoltcp and zerocopy, both of which have made significant
API changes since we last updated.

* Fix XDE test with latest falcon

* Chore: Update Zerocopy -> 0.7

* Update smoltcp -> 0.10

This required a bit more work than I'd hoped.

One significant benefit is that we can greatly simplify some of the DHCP
option insertion logic: we no longer need to perform surgery on built
options to remove/insert end markers etc. This also gives us some cause
to simplify and unify long options in our own `emit` function.

Smoltcp's refactor of IPv6 types are somewhat less ergonomic,
particularly for length computation.

* Remove some accidental testing leftovers.

* Respond to review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code cleanliness
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant