Calling this method is not unsafe, but implementing it is! The underlying guarantee is that the written URI reference SHALL be well-formed. If this method writes out something that is not a valid URI reference, the resulting behavior is undefined.
That this method is safe to use but "unsafe" to implement seems problematic in its current form.
This change creates a new automatically-assigned trait, AnyUriRefExt, and moves all of the methods from AnyUriRef that should not be overridden into it. The previous AnyUriRef::write_to method is made unsafe and renamed to AnyUriRef::write_to_unsafe. A new method, AnyUriRefExt::write_to is added that simply calls unsafe { self.write_to_unsafe(write) }.
This arrangement continues to allow the behavior of write_to to be changed, but instead of overriding it directly you must now override AnyUriRef::write_to_unsafe.
This change also deals with a similar problem with write_resolved, except in that case the entire method was simply moved to AnyUriRefExt to prevent it from being overridden at all.
Unfortunately this diff is a tad longer than I would have wanted because I ended up doing a slight reorganization of some of the methods in AnyUriRef. Sorry about that.
From the rustdocs for
AnyUriRef::write_to
:That this method is safe to use but "unsafe" to implement seems problematic in its current form.
This change creates a new automatically-assigned trait,
AnyUriRefExt
, and moves all of the methods fromAnyUriRef
that should not be overridden into it. The previousAnyUriRef::write_to
method is made unsafe and renamed toAnyUriRef::write_to_unsafe
. A new method,AnyUriRefExt::write_to
is added that simply callsunsafe { self.write_to_unsafe(write) }
.This arrangement continues to allow the behavior of
write_to
to be changed, but instead of overriding it directly you must now overrideAnyUriRef::write_to_unsafe
.This change also deals with a similar problem with
write_resolved
, except in that case the entire method was simply moved toAnyUriRefExt
to prevent it from being overridden at all.Fixes #8