You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are mostly a consequence of how they are used internaly (eg Header and Abi have Hash just because they used to be stored in a HashSet, Generics has Default because we use it once in conversions. We should aim to be more consistant and user facing in these traits.
What Traits I thing we should have and why?
The super clear ones:
Everything obviously need's Serialize and Deserialize
Clone and Debug are both super usefull, and I think everything should also Implement these, although it isn't required 1
Id needs Hash, Eq and PartialEq to be used as a HashMap key
Eq for everything. If we do PartialEq, we may as well do this,
Hash for almost everything. Currently Item and Crate cannot do this because they have HashMaps. If we realy wanted to, we could replace these with BTreeMap, but that would mean Ord for Id and possible slower perf. Theirs alot of things that make sense to put in a HashMap/HashSet key, and I thing just not having Item and Crate is fine. (I The fact that Type didn't implement Hash was the reason I looked into this).
Things to drop
I don't thing anything should implement Default, as I don't think it's usefull or clear.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]: Most types#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]:Id#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]:HeaderandAbi#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]:GenericsThese are mostly a consequence of how they are used internaly (eg
HeaderandAbihaveHashjust because they used to be stored in aHashSet,GenericshasDefaultbecause we use it once inconversions. We should aim to be more consistant and user facing in these traits.What Traits I thing we should have and why?
The super clear ones:
SerializeandDeserializeCloneandDebugare both super usefull, and I think everything should also Implement these, although it isn't required 1IdneedsHash,EqandPartialEqto be used as aHashMapkeyThe medium ones
PartialEqfor everything. It has clear semantics, and if we do rustdoc-json: replace jsondocck with jsondocckng #94140, it's essensialEqfor everything. If we doPartialEq, we may as well do this,Hashfor almost everything. CurrentlyItemandCratecannot do this because they haveHashMaps. If we realy wanted to, we could replace these withBTreeMap, but that would meanOrdforIdand possible slower perf. Theirs alot of things that make sense to put in aHashMap/HashSetkey, and I thing just not havingItemandCrateis fine. (I The fact thatTypedidn't implementHashwas the reason I looked into this).Things to drop
Default, as I don't think it's usefull or clear.cc @CraftSpider
@rustbot modify labels: +T-rustdoc +A-rustdoc-json
Footnotes
In practice, we depend on
CloneforItem, which means basicly everything else needs to beClone, but I'm almost certain this can be removed ↩