-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Packed Arrays could use some more trait impls #663
Comments
Definitely agree it makes sense to provide easier conversions between As mentioned in #297, we should make sure these satisfy common use cases. Otherwise, with this being marked good first issue, the risk is that newcomers just start working off the list of traits. Some things to keep in mind:
Interesting, we should remove that. Even without looking at the implementation, |
I'll update the issue to reflect some of these comments.
I think Having
|
I want pub struct SomeSmartParser {
input: std::io::Cursor<PackedByteArray>,
} In real code, this would probably be a generic (or maybe pub struct SomeSmartParser<R: std::io::Read + std::io::Seek> {
input: R,
}
let mut s = SomeSmartParser { input: std::io::Cursor::new(packed_byte_array) }; It's already possible to use |
I added @andreymal if we added What about
If not, that's a bit asymmetric -- should we then consider implementing |
You can't because you need to store the cursor position somewhere (but the |
Regarding An alternative is implementing our own |
But that implies writing can only be done by having an initially empty buffer and extending it? This will be inefficient due to reallocations, especially since packed arrays have no It also limits writing to the end of the array.
Hm yeah, maybe that's necessary. There's really no way to use standard cursors for writing custom data structures? What does this doc mean then?
|
(Anyway, I personally don't care about |
OK, so I suggest we can provide |
@andreymal what do you think? Would you be interested in a PR? 🙂 |
Not yet, I'm too busy currently |
For instance, you cannot currently do
This could be fixed with a
From<Vec<Vector3>>
impl forPackedVector3Array
.In general since packed arrays are very similar to
Vec
we could also take inspiration from whatVec
has implemented.See discussion below for more details.
Traits to implement:
From<Vec<T>>
From<[T; N]>
From<Array<T>>
From<PackedTArray> for Array<T>
Index
andIndexMut
, i think we can useI: SliceIndex
likeVec
does.IntoIterator
Write
, forPackedByteArray
only but preferably have a use-case firstOther trait impls we can consider:
Deref
andDerefMut
to[T]
. may conflict with Godot's api for packed arraysFrom<Box<[T]>>
,From<VecDeque<T>>
. We can already do this withcollect()
AsRef<[T]>
,AsMut<[T]>
,Borrow<[T]>
,BorrowMut<[T]>
. Should have a use-case firstAdditionally we apparently have
From<&VariantArray> for PackedVector3Array
etc, which is wrong. (looking at the implementation this might actually be UB).The text was updated successfully, but these errors were encountered: