#parser #iana #uri #namespaces

no-std urn

A crate for handling URNs (Unique Resource Names)

15 unstable releases (6 breaking)

0.7.0 Apr 8, 2023
0.5.1 Jan 7, 2023
0.5.0 Sep 29, 2022
0.4.0 Nov 4, 2021

#450 in Parser implementations

Download history 1029/week @ 2023-12-18 292/week @ 2023-12-25 1743/week @ 2024-01-01 2586/week @ 2024-01-08 4625/week @ 2024-01-15 2534/week @ 2024-01-22 4544/week @ 2024-01-29 4450/week @ 2024-02-05 3013/week @ 2024-02-12 2359/week @ 2024-02-19 3350/week @ 2024-02-26 4274/week @ 2024-03-04 3087/week @ 2024-03-11 3605/week @ 2024-03-18 1914/week @ 2024-03-25 2173/week @ 2024-04-01

10,822 downloads per month
Used in 14 crates (3 directly)

0BSD OR MIT OR Apache-2.0

60KB
1K SLoC

crates.io docs.rs

URN

A Rust crate for handling URNs. Parsing and comparison is done according to the spec (meaning only part of the URN is used for equality checks). Some RFCs define per-namespace lexical equivalence rules, those aren't taken into account here.

RFC2141 is more lenient than RFC8141 at times (and vice versa), care is taken to be able to parse either of them. When percent encoding URN components, the resulting URNs will always be valid for both RFC2141 and RFC8141 parsers. However, percent encoding/decoding rules may be different for some namespaces.

Serde support is available behind a feature flag. no_std support is available if you disable the default "std" feature. alloc is optional as well. UrnSlice is a borrowed URN, Urn is an owned URN. See docs.rs for documentation.

URNs have a surprising amount of obscure details to the point I'm not sure if other URN parsers can be trusted! Granted, there's very little of them because almost nobody really needs URNs...

Changelog

  • 0.1.0 - initial release
  • 0.1.1 - add FromStr impl
  • 0.2.0 - remove Urn::parse function in favor of FromStr, improved docs
  • 0.2.1 - remove files left over from 0.1
  • 0.3.0 - major implementation changes, remove Namespace (thanks to u/chris-morgan for help)
  • 0.3.1 - fix a panic on empty NSS and add "?=" terminator to r-component (both "?" and "=" can be part of r-component, but together they terminate it)
  • 0.3.2 - add Clone impl for Urn
  • 0.3.3 - more precise builder errors; reduce memory footprint by up to 15 bytes (but increase it by 5 bytes on 16-bit platforms)
  • 0.3.4 - Serde support by @callym
  • 0.4.0 - UrnBuilder::namespace -> UrnBuilder::nid
  • 0.5.0 - changed builder API to accept options for optional components, minor cleanup, fixed a couple potential minor bugs
  • 0.5.1 - fix a panic in case there wasn't a valid utf-8 char boundary 4 bytes into the string
  • 0.6.0 - add alloc feature, add UrnSlice type, add percent module, don't impl Deref<Target = str>. The crate is getting close to 1.0.
  • 0.7.0 - add support for deserializing non-'static UrnSlices, always encode valid RFC2141 URNs, check for empty string in percent::encode_*.

License

TL;DR do whatever you want.

Licensed under either the BSD Zero Clause License (https://opensource.org/licenses/0BSD), the Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0) or the MIT License (http://opensource.org/licenses/MIT), at your choice.

Dependencies

~185KB