@@ -157,45 +157,100 @@ impl Url {
157
157
}
158
158
}
159
159
160
+ pub fn set_origin < U : AsRef < str > > ( & mut self , input : U ) -> bool {
161
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
162
+ unsafe { ffi:: ada_set_origin ( self . url , input_with_0_terminate. as_ptr ( ) ) }
163
+ }
164
+
160
165
pub fn href ( & self ) -> & str {
161
166
unsafe { ffi:: ada_get_href ( self . url ) } . as_str ( )
162
167
}
163
168
169
+ pub fn set_href < U : AsRef < str > > ( & mut self , input : U ) -> bool {
170
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
171
+ unsafe { ffi:: ada_set_href ( self . url , input_with_0_terminate. as_ptr ( ) ) }
172
+ }
173
+
164
174
pub fn username ( & self ) -> & str {
165
175
unsafe { ffi:: ada_get_username ( self . url ) } . as_str ( )
166
176
}
167
177
178
+ pub fn set_username < U : AsRef < str > > ( & mut self , input : U ) -> bool {
179
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
180
+ unsafe { ffi:: ada_set_username ( self . url , input_with_0_terminate. as_ptr ( ) ) }
181
+ }
182
+
168
183
pub fn password ( & self ) -> & str {
169
184
unsafe { ffi:: ada_get_password ( self . url ) } . as_str ( )
170
185
}
171
186
187
+ pub fn set_password < U : AsRef < str > > ( & mut self , input : U ) -> bool {
188
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
189
+ unsafe { ffi:: ada_set_password ( self . url , input_with_0_terminate. as_ptr ( ) ) }
190
+ }
191
+
172
192
pub fn port ( & self ) -> & str {
173
193
unsafe { ffi:: ada_get_port ( self . url ) } . as_str ( )
174
194
}
175
195
196
+ pub fn set_port < U : AsRef < str > > ( & mut self , input : U ) -> bool {
197
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
198
+ unsafe { ffi:: ada_set_port ( self . url , input_with_0_terminate. as_ptr ( ) ) }
199
+ }
200
+
176
201
pub fn hash ( & self ) -> & str {
177
202
unsafe { ffi:: ada_get_hash ( self . url ) } . as_str ( )
178
203
}
179
204
205
+ pub fn set_hash < U : AsRef < str > > ( & mut self , input : U ) {
206
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
207
+ unsafe { ffi:: ada_set_hash ( self . url , input_with_0_terminate. as_ptr ( ) ) }
208
+ }
209
+
180
210
pub fn host ( & self ) -> & str {
181
211
unsafe { ffi:: ada_get_host ( self . url ) } . as_str ( )
182
212
}
183
213
214
+ pub fn set_host < U : AsRef < str > > ( & mut self , input : U ) -> bool {
215
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
216
+ unsafe { ffi:: ada_set_host ( self . url , input_with_0_terminate. as_ptr ( ) ) }
217
+ }
218
+
184
219
pub fn hostname ( & self ) -> & str {
185
220
unsafe { ffi:: ada_get_hostname ( self . url ) } . as_str ( )
186
221
}
187
222
223
+ pub fn set_hostname < U : AsRef < str > > ( & mut self , input : U ) -> bool {
224
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
225
+ unsafe { ffi:: ada_set_hostname ( self . url , input_with_0_terminate. as_ptr ( ) ) }
226
+ }
227
+
188
228
pub fn pathname ( & self ) -> & str {
189
229
unsafe { ffi:: ada_get_pathname ( self . url ) } . as_str ( )
190
230
}
191
231
232
+ pub fn set_pathname < U : AsRef < str > > ( & mut self , input : U ) -> bool {
233
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
234
+ unsafe { ffi:: ada_set_pathname ( self . url , input_with_0_terminate. as_ptr ( ) ) }
235
+ }
236
+
192
237
pub fn search ( & self ) -> & str {
193
238
unsafe { ffi:: ada_get_search ( self . url ) } . as_str ( )
194
239
}
195
240
241
+ pub fn set_search < U : AsRef < str > > ( & mut self , input : U ) {
242
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
243
+ unsafe { ffi:: ada_set_search ( self . url , input_with_0_terminate. as_ptr ( ) ) }
244
+ }
245
+
196
246
pub fn protocol ( & self ) -> & str {
197
247
unsafe { ffi:: ada_get_protocol ( self . url ) } . as_str ( )
198
248
}
249
+
250
+ pub fn set_protocol < U : AsRef < str > > ( & mut self , input : U ) -> bool {
251
+ let input_with_0_terminate = std:: ffi:: CString :: new ( input. as_ref ( ) ) . unwrap ( ) ;
252
+ unsafe { ffi:: ada_set_protocol ( self . url , input_with_0_terminate. as_ptr ( ) ) }
253
+ }
199
254
}
200
255
201
256
#[ cfg( test) ]
@@ -211,15 +266,33 @@ mod test {
211
266
out. href( ) ,
212
267
"https://username:[email protected] :9090/search?query#hash"
213
268
) ;
214
- assert_eq ! ( out. username( ) , "username" ) ;
215
- assert_eq ! ( out. password( ) , "password" ) ;
216
- assert_eq ! ( out. port( ) , "9090" ) ;
217
- assert_eq ! ( out. hash( ) , "#hash" ) ;
218
- assert_eq ! ( out. host( ) , "google.com:9090" ) ;
219
- assert_eq ! ( out. hostname( ) , "google.com" ) ;
220
- assert_eq ! ( out. pathname( ) , "/search" ) ;
221
- assert_eq ! ( out. search( ) , "?query" ) ;
222
- assert_eq ! ( out. protocol( ) , "https:" ) ;
269
+
270
+ assert ! ( out. set_username( "new-username" ) ) ;
271
+ assert_eq ! ( out. username( ) , "new-username" ) ;
272
+
273
+ assert ! ( out. set_password( "new-password" ) ) ;
274
+ assert_eq ! ( out. password( ) , "new-password" ) ;
275
+
276
+ assert ! ( out. set_port( "4242" ) ) ;
277
+ assert_eq ! ( out. port( ) , "4242" ) ;
278
+
279
+ out. set_hash ( "#new-hash" ) ;
280
+ assert_eq ! ( out. hash( ) , "#new-hash" ) ;
281
+
282
+ assert ! ( out. set_host( "yagiz.co:9999" ) ) ;
283
+ assert_eq ! ( out. host( ) , "yagiz.co:9999" ) ;
284
+
285
+ assert ! ( out. set_hostname( "domain.com" ) ) ;
286
+ assert_eq ! ( out. hostname( ) , "domain.com" ) ;
287
+
288
+ assert ! ( out. set_pathname( "/new-search" ) ) ;
289
+ assert_eq ! ( out. pathname( ) , "/new-search" ) ;
290
+
291
+ out. set_search ( "updated-query" ) ;
292
+ assert_eq ! ( out. search( ) , "?updated-query" ) ;
293
+
294
+ out. set_protocol ( "wss" ) ;
295
+ assert_eq ! ( out. protocol( ) , "wss:" ) ;
223
296
}
224
297
225
298
#[ test]
0 commit comments