|
20 | 20 | //! CURL ▏ 1471 ns/URL █████████████████████████
|
21 | 21 | //! ```
|
22 | 22 |
|
| 23 | +pub mod ffi; |
23 | 24 | mod idna;
|
| 25 | +pub use idna::Idna; |
24 | 26 |
|
25 | 27 | use std::{borrow, fmt, hash, ops};
|
26 | 28 | use thiserror::Error;
|
27 | 29 |
|
28 |
| -pub use idna::Idna; |
29 |
| - |
30 |
| -pub mod ffi { |
31 |
| - use std::ffi::c_char; |
32 |
| - |
33 |
| - #[repr(C)] |
34 |
| - pub struct ada_url { |
35 |
| - _unused: [u8; 0], |
36 |
| - _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, |
37 |
| - } |
38 |
| - |
39 |
| - #[repr(C)] |
40 |
| - pub struct ada_string { |
41 |
| - pub data: *const c_char, |
42 |
| - pub length: usize, |
43 |
| - } |
44 |
| - |
45 |
| - impl ada_string { |
46 |
| - pub fn as_str(self) -> &'static str { |
47 |
| - unsafe { |
48 |
| - let slice = std::slice::from_raw_parts(self.data.cast(), self.length); |
49 |
| - std::str::from_utf8_unchecked(slice) |
50 |
| - } |
51 |
| - } |
52 |
| - } |
53 |
| - |
54 |
| - #[repr(C)] |
55 |
| - pub struct ada_owned_string { |
56 |
| - pub data: *const c_char, |
57 |
| - pub length: usize, |
58 |
| - } |
59 |
| - |
60 |
| - impl AsRef<str> for ada_owned_string { |
61 |
| - fn as_ref(&self) -> &str { |
62 |
| - unsafe { |
63 |
| - let slice = std::slice::from_raw_parts(self.data.cast(), self.length); |
64 |
| - std::str::from_utf8_unchecked(slice) |
65 |
| - } |
66 |
| - } |
67 |
| - } |
68 |
| - |
69 |
| - #[repr(C)] |
70 |
| - pub struct ada_url_components { |
71 |
| - pub protocol_end: u32, |
72 |
| - pub username_end: u32, |
73 |
| - pub host_start: u32, |
74 |
| - pub host_end: u32, |
75 |
| - pub port: u32, |
76 |
| - pub pathname_start: u32, |
77 |
| - pub search_start: u32, |
78 |
| - pub hash_start: u32, |
79 |
| - } |
80 |
| - |
81 |
| - extern "C" { |
82 |
| - pub fn ada_parse(input: *const c_char, length: usize) -> *mut ada_url; |
83 |
| - pub fn ada_parse_with_base( |
84 |
| - input: *const c_char, |
85 |
| - input_length: usize, |
86 |
| - base: *const c_char, |
87 |
| - base_length: usize, |
88 |
| - ) -> *mut ada_url; |
89 |
| - pub fn ada_free(url: *mut ada_url); |
90 |
| - pub fn ada_free_owned_string(url: *mut ada_owned_string); |
91 |
| - pub fn ada_is_valid(url: *mut ada_url) -> bool; |
92 |
| - pub fn ada_can_parse(url: *const c_char, length: usize) -> bool; |
93 |
| - pub fn ada_can_parse_with_base( |
94 |
| - input: *const c_char, |
95 |
| - input_length: usize, |
96 |
| - base: *const c_char, |
97 |
| - base_length: usize, |
98 |
| - ) -> bool; |
99 |
| - pub fn ada_get_components(url: *mut ada_url) -> *mut ada_url_components; |
100 |
| - |
101 |
| - // Getters |
102 |
| - pub fn ada_get_origin(url: *mut ada_url) -> ada_owned_string; |
103 |
| - pub fn ada_get_href(url: *mut ada_url) -> ada_string; |
104 |
| - pub fn ada_get_username(url: *mut ada_url) -> ada_string; |
105 |
| - pub fn ada_get_password(url: *mut ada_url) -> ada_string; |
106 |
| - pub fn ada_get_port(url: *mut ada_url) -> ada_string; |
107 |
| - pub fn ada_get_hash(url: *mut ada_url) -> ada_string; |
108 |
| - pub fn ada_get_host(url: *mut ada_url) -> ada_string; |
109 |
| - pub fn ada_get_hostname(url: *mut ada_url) -> ada_string; |
110 |
| - pub fn ada_get_pathname(url: *mut ada_url) -> ada_string; |
111 |
| - pub fn ada_get_search(url: *mut ada_url) -> ada_string; |
112 |
| - pub fn ada_get_protocol(url: *mut ada_url) -> ada_string; |
113 |
| - |
114 |
| - // Setters |
115 |
| - pub fn ada_set_href(url: *mut ada_url, input: *const c_char, length: usize) -> bool; |
116 |
| - pub fn ada_set_username(url: *mut ada_url, input: *const c_char, length: usize) -> bool; |
117 |
| - pub fn ada_set_password(url: *mut ada_url, input: *const c_char, length: usize) -> bool; |
118 |
| - pub fn ada_set_port(url: *mut ada_url, input: *const c_char, length: usize) -> bool; |
119 |
| - pub fn ada_set_hash(url: *mut ada_url, input: *const c_char, length: usize); |
120 |
| - pub fn ada_set_host(url: *mut ada_url, input: *const c_char, length: usize) -> bool; |
121 |
| - pub fn ada_set_hostname(url: *mut ada_url, input: *const c_char, length: usize) -> bool; |
122 |
| - pub fn ada_set_pathname(url: *mut ada_url, input: *const c_char, length: usize) -> bool; |
123 |
| - pub fn ada_set_search(url: *mut ada_url, input: *const c_char, length: usize); |
124 |
| - pub fn ada_set_protocol(url: *mut ada_url, input: *const c_char, length: usize) -> bool; |
125 |
| - |
126 |
| - // Validators |
127 |
| - pub fn ada_has_credentials(url: *mut ada_url) -> bool; |
128 |
| - pub fn ada_has_empty_hostname(url: *mut ada_url) -> bool; |
129 |
| - pub fn ada_has_hostname(url: *mut ada_url) -> bool; |
130 |
| - pub fn ada_has_non_empty_username(url: *mut ada_url) -> bool; |
131 |
| - pub fn ada_has_non_empty_password(url: *mut ada_url) -> bool; |
132 |
| - pub fn ada_has_port(url: *mut ada_url) -> bool; |
133 |
| - pub fn ada_has_password(url: *mut ada_url) -> bool; |
134 |
| - pub fn ada_has_hash(url: *mut ada_url) -> bool; |
135 |
| - pub fn ada_has_search(url: *mut ada_url) -> bool; |
136 |
| - |
137 |
| - // IDNA methods |
138 |
| - pub fn ada_idna_to_unicode(input: *const c_char, length: usize) -> ada_owned_string; |
139 |
| - pub fn ada_idna_to_ascii(input: *const c_char, length: usize) -> ada_owned_string; |
140 |
| - } |
141 |
| -} |
142 |
| - |
143 | 30 | #[derive(Error, Debug)]
|
144 | 31 | pub enum Error {
|
145 | 32 | #[error("Invalid url: \"{0}\"")]
|
|
0 commit comments