Skip to content

Commit 21d1221

Browse files
alexpovelanonrig
authored andcommitted
chore: Undo Error for SetterResult
1 parent 6b41db2 commit 21d1221

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

examples/simple.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ada_url::Url;
22

3-
fn main() -> Result<(), Box<dyn std::error::Error>> {
3+
fn main() {
44
let url = Url::parse("http://www.google:8080/love#drug", None).expect("bad url");
55

66
println!("port: {:?}", url.port());
@@ -9,14 +9,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
99
println!("href: {:?}", url.href());
1010

1111
let mut url = url;
12-
13-
#[cfg(feature = "std")]
14-
url.set_port(Some("9999"))?;
15-
16-
#[cfg(not(feature = "std"))]
17-
url.set_port(Some("9999")).unwrap();
18-
12+
url.set_port(Some("9999")).expect("bad port");
1913
println!("href: {:?}", url.href());
20-
21-
Ok(())
2214
}

src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,14 @@ impl From<*mut ffi::ada_url> for Url {
179179
}
180180
}
181181

182-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Display)]
183-
#[cfg_attr(feature = "std", derive(derive_more::Error))] // error still requires std: https://github.com/rust-lang/rust/issues/103765
184-
pub struct SetterError;
185-
186-
type SetterResult = Result<(), SetterError>;
182+
type SetterResult = Result<(), ()>;
187183

188184
#[inline]
189185
const fn setter_result(successful: bool) -> SetterResult {
190186
if successful {
191187
Ok(())
192188
} else {
193-
Err(SetterError)
189+
Err(())
194190
}
195191
}
196192

@@ -299,6 +295,7 @@ impl Url {
299295
/// url.set_href("https://lemire.me").unwrap();
300296
/// assert_eq!(url.href(), "https://lemire.me/");
301297
/// ```
298+
#[allow(clippy::result_unit_err)]
302299
pub fn set_href(&mut self, input: &str) -> SetterResult {
303300
setter_result(unsafe { ffi::ada_set_href(self.0, input.as_ptr().cast(), input.len()) })
304301
}
@@ -327,6 +324,7 @@ impl Url {
327324
/// url.set_username(Some("username")).unwrap();
328325
/// assert_eq!(url.href(), "https://[email protected]/");
329326
/// ```
327+
#[allow(clippy::result_unit_err)]
330328
pub fn set_username(&mut self, input: Option<&str>) -> SetterResult {
331329
setter_result(unsafe {
332330
ffi::ada_set_username(
@@ -361,6 +359,7 @@ impl Url {
361359
/// url.set_password(Some("password")).unwrap();
362360
/// assert_eq!(url.href(), "https://:[email protected]/");
363361
/// ```
362+
#[allow(clippy::result_unit_err)]
364363
pub fn set_password(&mut self, input: Option<&str>) -> SetterResult {
365364
setter_result(unsafe {
366365
ffi::ada_set_password(
@@ -398,6 +397,7 @@ impl Url {
398397
/// url.set_port(Some("8080")).unwrap();
399398
/// assert_eq!(url.href(), "https://yagiz.co:8080/");
400399
/// ```
400+
#[allow(clippy::result_unit_err)]
401401
pub fn set_port(&mut self, input: Option<&str>) -> SetterResult {
402402
if let Some(value) = input {
403403
setter_result(unsafe { ffi::ada_set_port(self.0, value.as_ptr().cast(), value.len()) })
@@ -469,6 +469,7 @@ impl Url {
469469
/// url.set_host(Some("localhost:3000")).unwrap();
470470
/// assert_eq!(url.href(), "https://localhost:3000/");
471471
/// ```
472+
#[allow(clippy::result_unit_err)]
472473
pub fn set_host(&mut self, input: Option<&str>) -> SetterResult {
473474
setter_result(unsafe {
474475
ffi::ada_set_host(
@@ -507,6 +508,7 @@ impl Url {
507508
/// url.set_hostname(Some("localhost")).unwrap();
508509
/// assert_eq!(url.href(), "https://localhost/");
509510
/// ```
511+
#[allow(clippy::result_unit_err)]
510512
pub fn set_hostname(&mut self, input: Option<&str>) -> SetterResult {
511513
setter_result(unsafe {
512514
ffi::ada_set_hostname(
@@ -541,6 +543,7 @@ impl Url {
541543
/// url.set_pathname(Some("/contact")).unwrap();
542544
/// assert_eq!(url.href(), "https://yagiz.co/contact");
543545
/// ```
546+
#[allow(clippy::result_unit_err)]
544547
pub fn set_pathname(&mut self, input: Option<&str>) -> SetterResult {
545548
setter_result(unsafe {
546549
ffi::ada_set_pathname(
@@ -611,6 +614,7 @@ impl Url {
611614
/// url.set_protocol("http").unwrap();
612615
/// assert_eq!(url.href(), "http://yagiz.co/");
613616
/// ```
617+
#[allow(clippy::result_unit_err)]
614618
pub fn set_protocol(&mut self, input: &str) -> SetterResult {
615619
setter_result(unsafe { ffi::ada_set_protocol(self.0, input.as_ptr().cast(), input.len()) })
616620
}

0 commit comments

Comments
 (0)