Skip to content

refactor: modularize lib.rs - #458

Closed
alejandro-vaz wants to merge 7 commits into
servo:v2from
alejandro-vaz:refactor
Closed

refactor: modularize lib.rs#458
alejandro-vaz wants to merge 7 commits into
servo:v2from
alejandro-vaz:refactor

Conversation

@alejandro-vaz

@alejandro-vaz alejandro-vaz commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

closes #478

scope of this PR

the PR offloads the following files from lib.rs:

  • bytes.rs => the bytes feature and its implementations
  • comparisons.rs => Eq and Ord, total and partial
  • mallocsizeof.rs => regarding the feature malloc_size_of
  • rawsmallvec.rs => functionality regarding the raw type
  • references.rs => deref, asref, borrow
  • serde.rs => serialize / deserialize
  • taggedlen.rs => the tagged length

exports TaggedLen with the internals feature and makes RawSmallVec methods public

modifies rustfmt.toml a bit to make the style more consistent across the codebase

saves ~20 LOC

@alejandro-vaz alejandro-vaz added this to the v2-alpha.13 milestone Aug 27, 2026
@alejandro-vaz alejandro-vaz self-assigned this Aug 27, 2026
@alejandro-vaz
alejandro-vaz marked this pull request as ready for review August 27, 2026 15:08
@alejandro-vaz
alejandro-vaz requested a review from jdm August 27, 2026 15:09
@alejandro-vaz alejandro-vaz removed this from the v2-alpha.13 milestone Aug 29, 2026

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why all the formatting changes at the same time?

Comment thread src/tests.rs
let array = [99; 128];
let small_vec: SmallVec<u8, 128> = SmallVec::from(array);
assert_eq!(&*small_vec, vec![99u8; 128].as_slice());
assert_eq!(&*small_vec, Vec::from([99u8; 128]).as_slice());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's weird that changes like this are included.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

that's because rustfmt misunderstands the imports and it thinks that alloc::vec (importing the macro) would be the same as doing alloc::vec::{self} which is not, that's the module

it only happens when it's told to group imports

Comment thread Cargo.toml Outdated
bytes = { version = "1", optional = true, default-features = false }
serde_core = { version = "1.0.221", optional = true, default-features = false }
malloc_size_of = { version = "0.1.1", optional = true, default-features = false }
add-syntax = "0.1.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Eh?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

that's to make this simpler

#[cfg_attr(feature = "internals", prepend(pub))]
use {
    rawsmallvec::RawSmallVec,
    taggedlen::TaggedLen
};

instead of having two exactly-equal blocks but one with pub and feature flag and the other with negative feature flag and not pub

it's DRY

@jdm jdm Aug 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it's worth another dependency. I propose removing that cfg and adding a separate block like this for clarity:

#[cfg(feature = "internals")]
pub use { self::RawSmallVec, self::TaggedLen };

Comment thread rustfmt.toml Outdated
style_edition = "2024"
trailing_comma = "Never"
use_try_shorthand = true
where_single_line = true No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer to review these changes separately.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fair, reverted changes on rustfmt.toml

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have no issue with the restructuring, but I would like it to happen by itself.

Comment thread src/lib.rs
// Standard Rust vectors are already specialized.
SmallVec::<T, N>::from_vec(vec![elem; n])
// Standard Rust iterators are already specialized.
repeat_n(elem, n).collect()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we revert all changes that are not moving code around? It makes reviewing this PR require much more time.

@alejandro-vaz alejandro-vaz Aug 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sorry, that was because I had to remove the macro

it's just a few of those changes, not much, all else was formatting (the other one was making taggedlen public, and the methods of rawsmallvec public as well)

I don't think I can revert them all without engineering the diff

I'd be better throwing the branch and creating a new one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know it's annoying, but I really want to review focused PRs. A change that describes a new repo structure and just moves code between files is easy to review. A change that does several things at once is not.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

will open a new PR

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.

initial lib.rs modularization

2 participants