| 1 | #![allow(missing_debug_implementations)] |
| 2 | |
| 3 | //! Percent-encoders for URI/IRI components. |
| 4 | |
| 5 | use super::{table::*, Encoder, Table}; |
| 6 | |
| 7 | /// An encoder for URI userinfo. |
| 8 | #[derive(Clone, Copy)] |
| 9 | pub struct Userinfo(()); |
| 10 | |
| 11 | impl Encoder for Userinfo { |
| 12 | const TABLE: &'static Table = USERINFO; |
| 13 | } |
| 14 | |
| 15 | /// An encoder for IRI userinfo. |
| 16 | #[derive(Clone, Copy)] |
| 17 | pub struct IUserinfo(()); |
| 18 | |
| 19 | impl Encoder for IUserinfo { |
| 20 | const TABLE: &'static Table = IUSERINFO; |
| 21 | } |
| 22 | |
| 23 | /// An encoder for URI registered name. |
| 24 | #[derive(Clone, Copy)] |
| 25 | #[cfg_attr(fuzzing, derive(PartialEq, Eq))] |
| 26 | pub struct RegName(()); |
| 27 | |
| 28 | impl Encoder for RegName { |
| 29 | const TABLE: &'static Table = REG_NAME; |
| 30 | } |
| 31 | |
| 32 | /// An encoder for IRI registered name. |
| 33 | #[derive(Clone, Copy)] |
| 34 | pub struct IRegName(()); |
| 35 | |
| 36 | impl Encoder for IRegName { |
| 37 | const TABLE: &'static Table = IREG_NAME; |
| 38 | } |
| 39 | |
| 40 | /// An encoder for URI/IRI port. |
| 41 | #[derive(Clone, Copy)] |
| 42 | pub struct Port(()); |
| 43 | |
| 44 | impl Encoder for Port { |
| 45 | const TABLE: &'static Table = DIGIT; |
| 46 | } |
| 47 | |
| 48 | /// An encoder for URI path. |
| 49 | /// |
| 50 | /// `EStr` has [extension methods] for the path component. |
| 51 | /// |
| 52 | /// [extension methods]: super::EStr#impl-EStr<E>-1 |
| 53 | #[derive(Clone, Copy)] |
| 54 | pub struct Path(()); |
| 55 | |
| 56 | impl Encoder for Path { |
| 57 | const TABLE: &'static Table = PATH; |
| 58 | } |
| 59 | |
| 60 | /// An encoder for IRI path. |
| 61 | /// |
| 62 | /// `EStr` has [extension methods] for the path component. |
| 63 | /// |
| 64 | /// [extension methods]: super::EStr#impl-EStr<E>-1 |
| 65 | #[derive(Clone, Copy)] |
| 66 | pub struct IPath(()); |
| 67 | |
| 68 | impl Encoder for IPath { |
| 69 | const TABLE: &'static Table = IPATH; |
| 70 | } |
| 71 | |
| 72 | /// An encoder for URI query. |
| 73 | #[derive(Clone, Copy)] |
| 74 | pub struct Query(()); |
| 75 | |
| 76 | impl Encoder for Query { |
| 77 | const TABLE: &'static Table = QUERY; |
| 78 | } |
| 79 | |
| 80 | /// An encoder for IRI query. |
| 81 | #[derive(Clone, Copy)] |
| 82 | pub struct IQuery(()); |
| 83 | |
| 84 | impl Encoder for IQuery { |
| 85 | const TABLE: &'static Table = IQUERY; |
| 86 | } |
| 87 | |
| 88 | /// An encoder for URI fragment. |
| 89 | #[derive(Clone, Copy)] |
| 90 | pub struct Fragment(()); |
| 91 | |
| 92 | impl Encoder for Fragment { |
| 93 | const TABLE: &'static Table = FRAGMENT; |
| 94 | } |
| 95 | |
| 96 | /// An encoder for IRI fragment. |
| 97 | #[derive(Clone, Copy)] |
| 98 | pub struct IFragment(()); |
| 99 | |
| 100 | impl Encoder for IFragment { |
| 101 | const TABLE: &'static Table = IFRAGMENT; |
| 102 | } |
| 103 | |
| 104 | /// An encoder for URI data which preserves only [unreserved] characters |
| 105 | /// and encodes the others. |
| 106 | /// |
| 107 | /// [unreserved]: https://datatracker.ietf.org/doc/html/rfc3986#section-2.3 |
| 108 | #[derive(Clone, Copy)] |
| 109 | pub struct Data(()); |
| 110 | |
| 111 | impl Encoder for Data { |
| 112 | const TABLE: &'static Table = &UNRESERVED.or_pct_encoded(); |
| 113 | } |
| 114 | |
| 115 | /// An encoder for IRI data which preserves only [unreserved] characters |
| 116 | /// and encodes the others. |
| 117 | /// |
| 118 | /// [unreserved]: https://datatracker.ietf.org/doc/html/rfc3987#section-2.1 |
| 119 | #[derive(Clone, Copy)] |
| 120 | pub struct IData(()); |
| 121 | |
| 122 | impl Encoder for IData { |
| 123 | const TABLE: &'static Table = &UNRESERVED.or_pct_encoded().or_ucschar(); |
| 124 | } |