refactor: refactor some imports#734
Conversation
Summary of ChangesHello, 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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.rshas 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.
There was a problem hiding this comment.
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)
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)
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)
Moving datetime module to be with the other modules.
mod crc32;
mod datetime;
src/read.rs (11)
Importing is_dir from crate::spec.
use crate::result::{ZipError, ZipResult, invalid};
use crate::spec::is_dir;src/read.rs (17)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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 {
Update some import
no breaking changes with 8.2.0
ff001c6