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

SliceBox: allow Deref into &[T] #40

Merged
merged 1 commit into from May 28, 2015
Merged

Conversation

@jmesmon
Copy link
Contributor

jmesmon commented May 28, 2015

Allows more convenient use of SliceBox where one doesn't care whether
it represents a Vec or &[T] and can handle using a &[T].

Allows more convenient use of SliceBox where one doesn't care whether
it represents a Vec<T> or &[T] and can handle using a &[T].
@TyOverby
Copy link
Collaborator

TyOverby commented May 28, 2015

How are you using this in your code? The reason that I didn't add this impl is because slicebox should be used only for immediate encoding / decoding and shouldn't really be used outside of that, so there shouldn't be a case where you aren't 100% certain that it represents a Vec or &[T].

@jmesmon
Copy link
Contributor Author

jmesmon commented May 28, 2015

I'm using structs I encode/decode directly for things in my programs other than encoding and decoding.
Rather than create duplicates of all my encoded/decoded structs just to push the same data around, doing this was more convenient.

Note that there is already a (nearly identical) implementation of Deref for RefBox (which this code was based on) which, as far as I can see, is provided for similar uses.

I suppose what I'm getting at is that I didn't have a reason to force something to be a Vec instead of a &[u8], and adding this makes it possible (well, at least decreases the code overhead) of sharing functions that handle the encoded/decoded structs between sides of the encode/decode.

TyOverby added a commit that referenced this pull request May 28, 2015
SliceBox: allow Deref into &[T]
@TyOverby TyOverby merged commit 1e49e5a into servo:master May 28, 2015
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@TyOverby
Copy link
Collaborator

TyOverby commented May 28, 2015

Fair enough; thanks for the pull request!

@jmesmon jmesmon deleted the jmesmon:slicebox-deref branch May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.