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

Handling of str-like slice types #13

Open
piegamesde opened this issue Aug 23, 2023 · 1 comment
Open

Handling of str-like slice types #13

piegamesde opened this issue Aug 23, 2023 · 1 comment

Comments

@piegamesde
Copy link

Hi, I'm currently toying around with writing some wrappers around slice types, and quickly ran into the issue of how to be generic over all slices including str-like types: https://users.rust-lang.org/t/generic-bound-over-all-slice-types/98743

So I'd like to know, how does this crate handle the problem, or if it doesn't, have you explored the problem space before coming to the conclusion that this is the best solution for you? Alternatively, is supporting str something you'd like to see in the future?

@CAD97
Copy link
Owner

CAD97 commented Aug 24, 2023

This crate just uses an Element generic and deals in [Element]. I consider this crate essentially deprecated in favor of slice-dst, which defines a trait SliceDst which is implemented both for for<T> [T] and should be for str (but apparently I forgot to add that impl oops).

Your three options for being generic over slice types are:

  • Use [impl Sized] and exclude str (and other custom slice tails).
  • Use impl ?Sized and include all unsized types, but lack the ability to [into|from]_raw_parts the pointers.
  • Use a custom trait (e.g. SliceDst). On nightly: feature(ptr_metadata) and Pointee<Metadata = usize>.

I've been meaning to revisit and repolish the various pointer-utils crates, including slice-dst. I've not been eager to do so until feature(ptr_metadata) lands, as that has a large impact on what API I can provide, but maybe I'll decide to do the big cleanup. (The big notable improvement available is using addr_of!, and I want to provide a derive(SliceDst).)

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

No branches or pull requests

2 participants