Jid("foo@bar/baz") instead of Jid { normalized: "foo@bar/baz", at:
Some(3), slash: Some(7) }, which I find much more readable.
Same for BareJid and FullJid.
Paths are already patched in the workspace's [patch.crates-io] block.
Not sure why this was added in the first place.
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
By defining the variables in the parent scope, we can avoid one level of
indentation for the tuple, which makes things more readable.
Additionally, we don’t need to call .to_str() on the passed objects,
they automatically Deref to &str for the format!() call.
This is necessary because `into_inner()` as implemented on Jid
consumes the value. That means it cannot be called through Deref
(because that only takes a reference).
This does not matter much because users need to replace usages of these
anyway, but it's better to have it right here to not cause additional
confusion.
This moves InnerJid into Jid and reformulates BareJid and FullJid in
terms of Jid.
Doing this has the key advantage that FullJid and BareJid can deref to
and borrow as Jid. This, in turn, has the advantage that they can be
used much more flexibly in HashMaps. However, this is (as we say in
Germany) future music; this commit only does the internal reworking.
Oh and also, it saves 20% memory on Jid objects.
Fixes#122 more thoroughly, or rather the original intent behind it.
This provides a non-copying API, which is generally favourable. The
other accessors were removed, because the intent was to provide this
"most sensible" API via the "default" (i.e. shortest, most concisely
named) functions.
This introduces a str-like type for each of these, which will allow
returning a ref instead of the copied data from various methods in
{Full,Bare}Jid.
The use of a macro ensures that all types are declared consistently.
stringprep can make transformations to a JID, the most well-known one is
making the nodepart and domainpart lowercase but it does much more than
that.
It is extremely common to have to validate already-normalised JIDs
though, and since https://github.com/sfackler/rust-stringprep/pull/4
this is exactly what the stringprep crate does, by returning
Cow::Borrowed() for common ASCII-only cases.
This commit further reduces time spent by an additional -15%..-58% when
already using this stringprep improvement, in addition to the
89.5%..98.5% change brought by this improvement (and +1.3% total when
the JID isn’t normalised yet).
For instance, my own full JID parses in 1.83 µs before these changes,
132 ns with just the stringprep optimisation, and 46 ns with also this
commit, on an i7-8700K.