Skip to content

refactor: refactor some imports#734

Merged
Its-Just-Nans merged 37 commits into
masterfrom
more-refact
Mar 19, 2026
Merged

refactor: refactor some imports#734
Its-Just-Nans merged 37 commits into
masterfrom
more-refact

Conversation

@Its-Just-Nans

Copy link
Copy Markdown
Member

Update some import

no breaking changes with 8.2.0

cargo semver-checks --baseline-rev ff001c6f2a630580399ad8044a7925801ca16a98

ff001c6

@Its-Just-Nans Its-Just-Nans self-assigned this Mar 19, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on internal code restructuring to enhance modularity and improve no_std compatibility. Key data structures like DateTime and various ZIP block definitions have been moved to more appropriate modules, and import paths have been updated accordingly. These changes streamline the codebase without introducing any breaking API changes, as confirmed by semantic versioning checks.

Highlights

  • Refactored DateTime Struct: The DateTime struct, responsible for handling DOS timestamps, has been moved from src/types.rs to its own dedicated module, src/datetime.rs. This improves modularity and organization within the codebase.
  • Centralized ZIP Block Definitions: Low-level ZIP block definitions, including ZipCentralEntryBlock, ZipLocalEntryBlock, ZipDataDescriptorBlock, and Zip64DataDescriptorBlock, have been relocated from src/types.rs to src/spec.rs. This consolidates structural specifications in a single location.
  • Improved no_std Compatibility: Several std imports for formatting and memory operations have been replaced with their core equivalents (e.g., std::fmt to core::fmt, std::mem to core::mem), enhancing the library's compatibility with no_std environments.
  • Error Handling Consistency: The unsupported_zip_error helper function has been removed, and its call sites now directly return Err(ZipError::UnsupportedArchive(...)), leading to more explicit error handling.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR refactors imports from std:: to core:: to improve no_std compatibility. The changes are straightforward and appropriate for this goal.

Critical Issue Found:

  • src/datetime.rs has a test configuration bug that prevents tests from compiling (line 401: #[cfg(tests)] should be #[cfg(test)])

Summary:
The refactoring changes are correct and improve portability. Once the test configuration is fixed, this PR should be ready to merge after verifying that CI tests pass.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread src/datetime.rs Outdated
@Its-Just-Nans Its-Just-Nans changed the title More refact refactor: refactor some imports Mar 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the DateTime struct into its own module and updates various std imports to core for better no_std compatibility. It also moves several fixed-size block structs (ZipCentralEntryBlock, ZipLocalEntryBlock, ZipDataDescriptorBlock, Zip64DataDescriptorBlock) from src/types.rs to src/spec.rs to centralize specification-related definitions. Review comments highlight opportunities to remove redundant imports in src/read.rs, improve error handling by directly using ZipError::UnsupportedArchive instead of a helper function, and remove an unused helper function.

I am having trouble creating individual review comments. Click here to see my feedback.

src/legacy/shrink.rs (185)

medium

Using io::Error instead of std::io::Error is a good change to reduce dependencies when std isn't needed. This aligns with the goal of making the library more flexible and usable in no_std environments.

        .ok_or_else(|| io::Error::other("Cannot get prefix code"))?

src/lib.rs (21)

medium

Moving DateTime import to be with the other crate::datetime import.

pub use crate::spec::{ZIP64_BYTES_THR, ZIP64_ENTRY_THR};
pub use crate::types::{AesMode, System};

src/lib.rs (34)

medium

Moving datetime module to be with the other modules.

mod crc32;
mod datetime;

src/read.rs (11)

medium

Importing is_dir from crate::spec.

use crate::result::{ZipError, ZipResult, invalid};
use crate::spec::is_dir;

src/read.rs (17)

medium

Importing LittleEndianReadExt and path_to_string from crate::unstable.

use crate::types::{AesMode, AesVendorVersion, SimpleFileOptions, System, ZipFileData, ffi};
use crate::unstable::{LittleEndianReadExt, path_to_string};

src/read.rs (113-117)

medium

These imports are no longer needed here as they are already imported in src/lib.rs.

use crate::extra_fields::UnicodeExtraField;
use crate::result::ZipError::InvalidPassword;
use crate::spec::is_dir;
use crate::types::ffi::{S_IFLNK, S_IFREG};
use crate::unstable::{LittleEndianReadExt, path_to_string};
pub use zip_archive::ZipArchive;

src/read.rs (370-373)

medium

Using ZipError::UnsupportedArchive directly is clearer and more idiomatic than calling a separate function.

        if let CompressionMethod::Unsupported(_) = data.compression_method {
            return Err(ZipError::UnsupportedArchive(
                "Compression method not supported",
            ));

src/read.rs (735-737)

medium

Using ZipError::UnsupportedArchive directly is clearer and more idiomatic than calling a separate function.

        if dir_info.disk_number != dir_info.disk_with_central_directory {
            return Err(ZipError::UnsupportedArchive(
                "Support for multi-disk files is not implemented",

src/read.rs (1392-1394)

medium

This unsupported_zip_error function is no longer used and can be removed.

/// Parse a central directory entry to collect the information for the file.
pub(crate) fn central_header_to_zip_file<R: Read + Seek>(

src/read.rs (2051)

medium

Using ffi::S_IFREG instead of S_IFREG is a good change to reduce dependencies when std isn't needed. This aligns with the goal of making the library more flexible and usable in no_std environments.

            .compression_method(self.compression())
            .unix_permissions(self.unix_mode().unwrap_or(0o644) | ffi::S_IFREG)
            .last_modified_time(

src/types.rs (17)

medium

Using core::fmt instead of std::fmt reduces the dependency on the standard library, which is beneficial for no_std environments.

use crate::zipcrypto::EncryptWith;
use core::fmt::Debug;
use core::fmt::Display;

src/types.rs (354)

medium

Using ffi::S_IFDIR instead of S_IFDIR is a good change to reduce dependencies when std isn't needed. This aligns with the goal of making the library more flexible and usable in no_std environments.

        } else if self
            .unix_mode()
            .is_some_and(|mode| mode & ffi::S_IFDIR == ffi::S_IFDIR)

src/types.rs (768)

medium

Using core::fmt instead of std::fmt reduces the dependency on the standard library, which is beneficial for no_std environments.

impl Display for AesMode {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

src/types.rs (817)

medium

Using ffi to access the constant.

        let mut data = ZipFileData {
            system: System::Dos,
            external_attributes: (ffi::S_IFLNK | 0o777) << 16,

src/types.rs (829-831)

medium

Using ffi to access the constant.

        data.external_attributes = 0x10; // DOS directory bit
        data.system = System::Dos;
        assert_eq!(data.unix_mode().unwrap() & 0o170000, ffi::S_IFDIR);

src/zipcrypto.rs (58)

medium

Using core::fmt instead of std::fmt reduces the dependency on the standard library, which is beneficial for no_std environments.

    #[cfg(any(test, fuzzing))]
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

src/zipcrypto.rs (65)

medium

Using core::fmt instead of std::fmt reduces the dependency on the standard library, which is beneficial for no_std environments.

    #[cfg(not(any(test, fuzzing)))]
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

@Its-Just-Nans Its-Just-Nans enabled auto-merge March 19, 2026 05:16
@Its-Just-Nans Its-Just-Nans added this pull request to the merge queue Mar 19, 2026
Merged via the queue into master with commit cde9e1b Mar 19, 2026
130 checks passed
@Its-Just-Nans Its-Just-Nans deleted the more-refact branch March 19, 2026 10:17
@Pr0methean Pr0methean mentioned this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant