no_alloc take Ⅲ
Created by: ticki
Now, there are three URL representations, all of which tracks both the scheme and the reference, such that reparsing is unnecessary:
-
Url
: A struct with two string slices. It is obviously unowned, and you have to track the lifetime. You can convert a&str
to anUrl
inO(n)
, it simply requires finding the:
, and taking two slices. This can be casted into the forms below by using one of the built-in methods. -
OwnedUrl
: This keeps two heap-allocated, ownedString
s representing the scheme and the reference. This is useful in a number of scenarios (whenUrl
isn't sufficient). There is currently relatively few methods defined on it, so to manipulate it, useas_url()
, which converts theOwnedUrl
to anUrl
. -
CowUrl
: An Copy-On-Write (CoW) URL, which is useful whenever heap allocation is conditional, that is, heap allocation is only necessary in a limited number of cases.
Url
is used for arguments. OwnedUrl
is used for unconditional manipulation. CowUrl
is used for conditional manipulation.