Commit graph

126 commits

Author SHA1 Message Date
Chris Morgan ff0fd8d0cf Narrow an unsafe block to the minimum
This was necessary in the days of the raw module, when inserting to the
raw map was the unsafe operation rather than getting mutable access to
the raw map, to which I have changed it now.
2022-01-26 00:57:40 +11:00
Chris Morgan 0316c0faea 1.0.0-beta.1
Not 1.0.0 after all, but let’s call it 1.0.0-beta.1 rather than 0.13.0.
2022-01-26 00:20:30 +11:00
Chris Morgan fe838bbc35 Remove Travis config (travis-ci.org has ceased)
Turns out travis-ci.org ceased building last year, and I either never
heard or had quite forgotten. I don’t care enough to sort out anything
else (I like the simple ./test script I wrote), so I’m just ditching it.

So much for the effort I put into updating this nicely today!
2022-01-26 00:20:30 +11:00
Chris Morgan c166d5c149 Make README more approachable, give example 2022-01-26 00:16:15 +11:00
Chris Morgan 983fc42114 Unravel another obsolete macro
With the removal of the raw module, it serves no more purpose.
2022-01-26 00:16:15 +11:00
Chris Morgan 836f984acd Add Entry::{or_default, and_modify}
They were stabilised in 1.28.0 and 1.27.0.
2022-01-26 00:16:15 +11:00
Chris Morgan 27eca55182 Replace the raw module with just hash_map
When I implemented Extend<Box<A>> for Map<A>, I thought:
can I implement Extend<(TypeId, Box<A>)> for RawMap<A>,
as HashMap<K, V> implements Extend<(K, V)>?
No, I responded, for insert is unsafe,
and a trait implementation cannot be marked unsafe.
Then said I, hang on, why is insert unsafe?
For by analogy with pointers, creating a dangling pointer is safe,
it’s only dereferencing it that’s unsafe;
so too here could insertion be safe and retrieval unsafe.
Then I realised: RawMap is actually completely safe, of itself;
the reason the unsafety is needed is AsMut<RawMap<A>> for Map<A>:
that retrieval is defined as safe, so insertion need be done delicately.

And so I consulted with myself and wondered:
Would it not be better to drop AsMut,
exposing rather an `unsafe fn as_raw_mut`?
For `AsRef<RawMap<A>>` and `Into<RawMap<A>>` may yet be safe,
yet this would take RawMap towards parity with HashMap.

And yet further went I,
descending into depths unplumbed these five years,
saying unto myself:
Wherefore RawMap<A> at all?
Why not rather HashMap<TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>,
accessed freely and safely by reference or Into,
and unsafely as discussed in the previous stanza
(if I may call it such)?
Striving to understand the matter,
it was a wearisome effort,
and I could not.
I consulted with 143ee06268,
yet with the passage of nigh seven years it was not able to tell me
just why I had thought this might be a good idea.
For lo, those were the benighted ages before Rust 1.0.0,
though the glimmer of that bright dawn danced on the horizon
like the latter part of an arctic winter.

And so, casting away the trammels of history
I forged a new path.
For lo! had I not even then declared it
“not necessarily the final form”?
Casting RawMap away from me and clasping HashMap to my bosom,
I found the required diff in lib.rs
such a delicate thing,
so slight.
It was pleasing in my eyes, and so forthwith I decided:
hew down the unwanted abstraction,
and bind it with a band of iron and bronze,
that it may grow no more.
So need I not add more features to it,
mere shadows of the true HashMap underneath.

Oh fortunate day!
Three-hundred-odd lines removed,
(though more detailed comments offset this,
so that the end result is more like 223,)
and simplicity restored.
Well, except for this fly in the ointment:
std versus hashbrown.
Woe unto the person who calls a raw map std::collections::HashMap,
for when another comes and enables hashbrown,
the first shall crumble into nothingness and errors most distressing.
The mitigation of this is `pub type RawMap<A>`,
augmented by the very truth that,
few using this feature,
few may stumble!
Yet there are difference betwixt the twain,
seen in my cfg branching on VacantEntry and OccupiedEntry,
and this *is* a very mild violation of the principle of strictly additive features.

There ’tis: the tale of an abstraction unravelled.
Unravelled? Feels more like “not ravelled” rather than undoing ravelling.
Deravelled? Disravelled?
I shall but brand the abstraction a dead princess, as it were,
and this my pavane pour un infante défunte.

And if you, dear reader—
if reader there be of this screed that has grown rather longer than originally anticipated but also probably more entertaining if you don’t mind this sort of thing or share a similar sense of humour to me—
have aught to opine on the matter,
You know my email address.
2022-01-26 00:16:15 +11:00
Chris Morgan 2bcbd9c551 HashMap feature parity: impl Extend, notes on more 2022-01-26 00:16:15 +11:00
Chris Morgan 0a1c85f865 no_std support
I’m quite pleased with how this has turned out.

Given the stability-despite-instability of hashbrown (that the API
surface we’re depending on hasn’t changed since 0.1.1), and the
deliberate altered SemVer guarantees for it, it was very tempting
to leave the hashbrown range open, `version = ">=0.1.1"` or at least
`version = ">=0.1.1, <1"`, but for some reason or other I ended up
deciding not to. I’m still of two minds about it, really.
2022-01-26 00:16:15 +11:00
Chris Morgan 98f2816e62 Change std to core where possible
Only one thing from std left: HashMap.
2022-01-26 00:16:15 +11:00
Chris Morgan 39168419e8 Switch from 2015 edition to 2018
1.34 is safe for that.
2022-01-26 00:16:15 +11:00
Chris Morgan e245a23bab Normalise style for next release in changelog
Full sentences, past tense.

And updated the bench thing ’cos the situation has changed since I wrote
it, even though it was still completely true.
2022-01-26 00:16:15 +11:00
Chris Morgan 1e5c62d8f8 Exclude unnecessary files from the package 2022-01-26 00:16:15 +11:00
Chris Morgan 0d9f2cfe46 Remove obsolete items from .gitignore
Now the records are ancient.
2022-01-26 00:16:15 +11:00
Chris Morgan 692fe912db Add a local testing script 2022-01-26 00:16:15 +11:00
Chris Morgan 8bc7c76088 Implement From, not Into 2022-01-26 00:16:15 +11:00
Chris Morgan 2d5be08822 More documentation tweaks to clarify and explain 2022-01-26 00:16:15 +11:00
Chris Morgan 764038fe6e Drop anymap::Any in favour of std::any::Any
Casualties: Any + Sync, CloneAny + Sync. Acceptable losses.
2022-01-26 00:16:15 +11:00
Chris Morgan b07b62fd4d Flatten anymap::any out of existence
Namespaces are one honking great idea, but flat is better than nested.

anymap::raw still makes sense.
2022-01-26 00:16:15 +11:00
Chris Morgan 8f041216ba Tweak docs, especially around safety
No semantic changes.
2022-01-26 00:16:15 +11:00
Chris Morgan 7866ca8d77 Make TypeIdHasher safe, bump MSRV
Wait a few years and nice things stabilise!

• u64::from_ne_bytes([u8; 8]) is stable in 1.32.0
• TryFrom<&[u8]> for [u8; 8] is stable in 1.34.0

(There are other things I’m touching today that also require a more mild
MSRV bump, but this is the most I *need* at this time.)
2022-01-26 00:16:15 +11:00
Chris Morgan 521fbfe6bc Refactor to avoid a spurious compatibility warning
Explained in the SAFETY comment. I’m not happy about *doing* this, but
it will make *using* this crate easier, since future-compatibility lints
make noise on bin crate builds, so this was polluting other people’s
code and making life harder for users.

I have traded one evil (a spurious warning) for another (unsafe code).
2022-01-26 00:16:15 +11:00
Chris Morgan 0656f18289 Unravel the parbroken define! macro
Turns out its commenting technique was completely broken—the attributes
have to be attached to an item *inside* the macro, not outside. And
judging by https://docs.rs/anymap/0.11.0/anymap/any/trait.CloneAny.html,
it was broken from the start, and I never noticed. Sigh. Now, you get a
warning that it’s not going to work like you want. Good stuff.

Well, that macro wasn’t a great idea anyway. Doing without it ends up a
little longer, and risks inconsistent editing, but is decidedly easier
to read.
2022-01-26 00:16:15 +11:00
Chris Morgan bf29e608d9 No more bare trait objects: use dyn Trait syntax 2022-01-26 00:16:15 +11:00
Chris Morgan 7719a1c61b Refresh Cargo.toml, README.md
Remove superfluous things, update useful things.
2022-01-26 00:16:15 +11:00
Chris Morgan 8ebb2d7e04 Add the BlueOak-1.0.0 license
I prefer to use BlueOak-1.0.0 now; It wasn’t around back in 2017.

There are a number of commits in this repository not made by me, all
from before Rust 1.0.0:

• f1710353a0 (Robert Straw; trivial: matching std enum namespacing breakage)
• de09145309 (Robert Straw; trivial: std enum namespacing breakage)
• 2e37f0d1ae (Jonathan Reem; added AnyMap::contains, which had become obvious for Rust collection parity)
• 8b30c87fe6 (tivek; trivial: Rust syntax change in integer literal inference)
• c9d196be5f (Jonathan Reem; trivial: version bump)
• 330bc5aa1e (Jonathan Reem; not creative and largely no longer present: introduced Cargo support, tweaked Makefile)
• a9b1e31b70 (Tomas Sedovic; nigh-trivial and no longer present: Collection and Mutable trait implementations)
• eecc4a4b75 (Jonathan Reem; trivial: Rust syntax change)
• d51aff5064 (Jonathan Reem; trivial: rustc lint change)
• 56113c63b0 (Jonathan Reem; trivial: Rust syntax change)

All but one of these are definitely trivial, obvious, and in the context
of the project and ecosystem not creative works (⅌ copyright doctrine
definition); or else no longer present. The one arguable exception is
2e37f0d1ae, adding AnyMap::contains, since
I hadn’t added a contains method; but its *definition* is trivial with
only one possible implementation, and subsequent to that time I did go
through and check for parity with HashMap methods, to say nothing of the
code having changed shape quite a bit since then too. Therefore I’m
content to consider it immaterial for relicensing.
2022-01-26 00:16:15 +11:00
Chris Morgan 8abad057b0 Revert "removed unsafe code in favor of explicit assert"
This reverts commit 479d756c99.

There’s nothing wrong with this patch, but I had never pulled this
commit to my local repository and had completely forgotten about it, and
today removed the unsafe code in a *different* direction that I like
better (`bytes.try_into().map(|bytes| u64::from_ne_bytes(bytes))`), so
reverting it so I can cleanly rebase is just easier for me!
2022-01-26 00:12:16 +11:00
Chris Morgan 6dab74b721
Merge pull request #32 from hellow554/master
removed unsafe code in favor of explicit assert
2018-11-27 12:47:11 +11:00
Marcel Hellwig 479d756c99 removed unsafe code in favor of explicit assert 2018-11-13 11:27:14 +01:00
Chris Morgan 0850f5ec36 Implement Default on Map
It was implemented on RawMap, and I’m not sure quite why it wasn’t
implemented on Map. I can’t think of any reason *not* to, though, so we
might as well.

Closes #30. Thanks to Maxwell Koo <mjkoo90@gmail.com> for the fix.
2017-10-02 14:32:51 +11:00
Chris Morgan f5e887ef63 Add a note about unsafety. 2017-07-07 10:55:37 +10:00
Chris Morgan 9e3715152f Remove an obsolete note from the README 2017-07-07 10:55:36 +10:00
Chris Morgan b3811cf0d1 Remove the bench Cargo feature as superfluous
A better pattern is to put benchmarks in the `benches` directory;
that way, `cargo test` won’t pick them up by default,
and so it won’t fail on the stable and beta channels.
2017-07-07 10:55:35 +10:00
Chris Morgan eae3d22312 Add a changelog. 2017-07-07 10:55:34 +10:00
Chris Morgan 1374cacb41 Remove obsolete rust-ci docs uploading
We use docs.rs these days. No manual work in it, either. Yay!
2017-07-07 10:55:33 +10:00
Chris Morgan 2173c81567 0.12.1 2017-01-20 18:13:13 +05:30
Chris Morgan 34028c35e7 Make clippy happy. 2017-01-20 18:10:55 +05:30
Chris Morgan b549457d62 Put in a bunch of #[inline] attributes on fns.
Somewhere along the path I didn’t mark some functions as `#[inline]`
which they should probably be.

Small but visible benchmark improvements, but within ε so low
confidence.
2016-06-11 13:30:33 +10:00
Chris Morgan ec57ec49be Reduce the work for rustc in the benchmarks.
This *does* mean that they no longer function as tests, which was
deliberate, but rustc is just too slow with the assertions in there as
well. If I care, I can make variants of it that actually test. For now,
I’m sufficiently happy with it.
2016-06-11 13:28:30 +10:00
Chris Morgan c52281b376 Use raw pointers for downcasting, not TraitObject
This mirrors a change in mopa.
2016-06-11 10:46:30 +10:00
Chris Morgan 0c3026f7de Add more benchmarking
Including a rustc/llvm pathalogical case.
2016-06-11 10:06:13 +10:00
Chris Morgan 839a6bc6e8 Remove superfluous Clone bound on Entry methods.
Thanks to @Kimundi for pointing this out. I presume (without checking)
that they got added along with the CloneAny stuff by accident.

Closes #26.
2016-06-11 09:30:24 +10:00
Chris Morgan 8e413e2065 Remove now-unnecessary #[allow]s. 2016-06-11 09:29:32 +10:00
Chris Morgan f38113a9cf Make Clippy happy. 2016-04-18 15:00:43 +10:00
Chris Morgan f63062acc6 Keep Clippy happy. 2016-03-07 00:13:47 +11:00
Chris Morgan 724f94758d Fix order of ptr::copy_nonoverlapping parameters.
Clippy helped me spot this. It didn’t cause any bugs, just bad
performance as all keys would hash to 0 and thus end up in the same
bucket.
2016-03-07 00:11:37 +11:00
Chris Morgan f1ea6f1cf9 0.12.0 2016-03-05 13:31:53 +11:00
Chris Morgan 85398300ee s/unstable/bench/ in travis config 2016-03-05 13:27:54 +11:00
Chris Morgan 016d324c51 Rename "unstable" feature to "bench".
Benchmarking is the only thing that requires unstable Rust in the
library any more. Yay!
2016-03-05 13:13:19 +11:00
Chris Morgan 548ee2a5f2 Ungate drain iterator (stable in Rust 1.6.0). 2016-03-05 12:58:49 +11:00