/rust/registry/src/index.crates.io-1949cf8c6b5b557f/iri-string-0.7.8/src/spec/internal.rs
Line | Count | Source |
1 | | //! A private module for sealed trait and internal implementations. |
2 | | //! |
3 | | //! Note that this MUST be a private module. |
4 | | //! See [Rust API Guidelines][sealed-trait] about the necessity of being private. |
5 | | //! |
6 | | //! [sealed-trait]: |
7 | | //! https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed |
8 | | |
9 | | use crate::parser::char::is_ucschar; |
10 | | use crate::spec::{IriSpec, UriSpec}; |
11 | | |
12 | | /// A trait to prohibit user-defined types from implementing `Spec`. |
13 | | /// |
14 | | /// About sealed trait, see [Rust API Guidelines][future-proofing]. |
15 | | /// |
16 | | /// [future-proofing]: https://rust-lang.github.io/api-guidelines/future-proofing.html |
17 | | pub trait Sealed: SpecInternal {} |
18 | | |
19 | | impl Sealed for IriSpec {} |
20 | | impl Sealed for UriSpec {} |
21 | | |
22 | | /// Internal implementations for spec types. |
23 | | pub trait SpecInternal: Sized { |
24 | | /// Checks if the given non-ASCII character matches `unreserved` or `iunreserved` rule. |
25 | | #[must_use] |
26 | | fn is_nonascii_char_unreserved(c: char) -> bool; |
27 | | /// Checks if the given character matches `iprivate` rule. |
28 | | #[must_use] |
29 | | fn is_nonascii_char_private(c: char) -> bool; |
30 | | } |
31 | | |
32 | | impl SpecInternal for IriSpec { |
33 | | #[inline] |
34 | 0 | fn is_nonascii_char_unreserved(c: char) -> bool { |
35 | 0 | is_ucschar(c) |
36 | 0 | } |
37 | | |
38 | 0 | fn is_nonascii_char_private(c: char) -> bool { |
39 | 0 | matches!( |
40 | 0 | u32::from(c), |
41 | 0 | 0xE000..=0xF8FF | |
42 | 0 | 0xF_0000..=0xF_FFFD | |
43 | 0 | 0x10_0000..=0x10_FFFD |
44 | | ) |
45 | 0 | } |
46 | | } |
47 | | |
48 | | impl SpecInternal for UriSpec { |
49 | | #[inline] |
50 | 0 | fn is_nonascii_char_unreserved(_: char) -> bool { |
51 | 0 | false |
52 | 0 | } Unexecuted instantiation: <iri_string::spec::UriSpec as iri_string::spec::internal::SpecInternal>::is_nonascii_char_unreserved Unexecuted instantiation: <iri_string::spec::UriSpec as iri_string::spec::internal::SpecInternal>::is_nonascii_char_unreserved |
53 | | |
54 | | #[inline] |
55 | 0 | fn is_nonascii_char_private(_: char) -> bool { |
56 | 0 | false |
57 | 0 | } Unexecuted instantiation: <iri_string::spec::UriSpec as iri_string::spec::internal::SpecInternal>::is_nonascii_char_private Unexecuted instantiation: <iri_string::spec::UriSpec as iri_string::spec::internal::SpecInternal>::is_nonascii_char_private |
58 | | } |