Skip to content

deprecate as_slice and as_mut_slice? #736

Closed

Description

@alejandro-vaz

as_slice and as_mut_slice are accessors to the underlying slice represented by the smallvec

idiomatic rust consistently prefers trait implementations, such as AsRef and AsMut to be used over bespoke helper methods

since we only implement AsRef<[T]> and AsMut<[T]>, and not other reference-to-reference conversions, calling as_ref and as_mut on a smallvec is unambiguous

request for comments

Activity

  1. added this to the v2-beta.3 milestone on Oct 5, 2026
  2. Ankit-cs commented on Oct 7, 2026

    @Ankit-cs
    Contributor

    Assign this to me

  3. Ankit-cs commented on Oct 8, 2026

    @Ankit-cs
    Contributor

    I’d love to get some feedback on a few points since this is a request for comments:
    @alejandro-vaz

    Complete removal vs Deprecation: Since v2 allows for breaking API changes, should we completely remove as_slice and as_mut_slice from the codebase, or just mark them with #[deprecated(since="...", note="use .as_ref() instead")] to give users a smoother migration path?
    Parity with standard Vec: The standard library Vec actually does have both as_slice() and as_mut_slice() methods for convenience, despite also implementing AsRef/AsMut. Does SmallVec intentionally want to diverge from Vec's API surface here to be strictly idiomatic?
    Other Structs: If we remove/deprecate them on SmallVec, should we also remove as_slice() from other structs like IntoIter and Drain for consistency?
    Let me know what you prefer, and I'll go ahead and implement it!

  4. alejandro-vaz commented on Oct 8, 2026

    @alejandro-vaz
    CollaboratorAuthor

    for now we will deprecate it. in rc I'll open an issue group to see which of the deprecations we should remove. these two probably won't be removed but just marked as deprecated on v2 release

    Vec wouldn't be able to deprecate as_slice and as_mut_slice even if they aren't fully idiomatic because of backwards compatibility and the backlash it will get from people in the community that haven't heard about idiomatic rust

    SmallVec is similar to Vec but not Vec. we can break backwards compatibility and we will do it shamelessly when it is appropriate

    I do think we should simply deprecate it from all the structs that use it for now

    the attribute would be: #[deprecated(since="2.0.0-beta.3", note="use <SmallVec<Item, INLINE, Heap> as AsRef<[Item]>>::as_ref instead")] or something like that, copy exactly the wording on src/macros.rs

    removing the methods fully would be too big of a sudden change, but is definitely the eventual goal

  5. Ankit-cs commented on Oct 8, 2026

    @Ankit-cs
    Contributor

    OK I will try my best to do it

  6. alejandro-vaz commented on Oct 14, 2026

    @alejandro-vaz
    CollaboratorAuthor

    @Ankit-cs how is it going??

    please do not take an issue if you are not available. it's okay but leave a notice you are not available

  7. Ankit-cs commented on Oct 15, 2026

    @Ankit-cs
    Contributor

    @alejandro-vaz like any discord channel i can connect directly to you

  8. Ankit-cs commented on Oct 15, 2026

    @Ankit-cs
    Contributor

    Hi @alejandro-vaz, sorry for the delay! I am working on adding the #[deprecated(since = "2.0.0-beta.3", ...)] attributes to as_slice and as_mut_slice across SmallVec, IntoIter, and Drain, and updating any internal usages/tests.Lookig for feedback."

  9. alejandro-vaz commented on Oct 15, 2026

    @alejandro-vaz
    CollaboratorAuthor

    @alejandro-vaz like any discord channel i can connect directly to you

    just email me or leave a comment somewhere

  10. Ankit-cs commented on Oct 15, 2026

    @Ankit-cs
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

good first issueGood for a first contributorhelp wantedNo clear candidate to implement itr-refactorrelated to refactoring

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions