Skip to content

no_alloc take Ⅲ

Jeremy Soller requested to merge ticki:master into master

Created by: ticki

Now, there are three URL representations, all of which tracks both the scheme and the reference, such that reparsing is unnecessary:

  1. Url: A struct with two string slices. It is obviously unowned, and you have to track the lifetime. You can convert a &str to an Url in O(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.
  2. OwnedUrl: This keeps two heap-allocated, owned Strings representing the scheme and the reference. This is useful in a number of scenarios (when Url isn't sufficient). There is currently relatively few methods defined on it, so to manipulate it, use as_url(), which converts the OwnedUrl to an Url.
  3. 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.

Merge request reports