Skip to content

Commit 462ac5e

Browse files
committed
Remove the result implementations and change documentation
1 parent 46d907f commit 462ac5e

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

godot-core/src/classes/manual_extensions.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,44 +91,39 @@ impl Error {
9191
/// This is a convenience method that may be used to convert this type into one that can be used with the try operator (`?`)
9292
/// for easy short circuiting of Godot `Error`s.
9393
///
94-
/// To assist with this, `Result<(), Error>` has [a `ToGodot` implementation](ToGodot#impl-ToGodot-for-Result%3C(),+Error%3E)
95-
/// that turns it back into an `Error` on Godot's side, so that it can be used as the return value of `#[func]` functions.
94+
/// ```
95+
/// use godot::global::Error;
96+
///
97+
/// assert_eq!(Error::OK.err(), Ok(()));
98+
/// assert_eq!(Error::FAILED.err(), Err(Error::FAILED));
99+
/// ```
96100
pub fn err(self) -> Result<(), Self> {
97101
if self == Error::OK { Ok(()) } else { Err(self) }
98102
}
99103

100104
/// Creates an `Error` from a `Result<(), Error>`, the inverse of [`.err()`](Self::err).
101-
///
105+
///
102106
/// `Ok(())` becomes `Error::OK`, and `Err(e)` becomes `e`.
107+
///
108+
/// This can be used to implement "makeshift try blocks",
109+
/// or somehow else process the return value of a function that returns `Result<(), Error>`.
110+
/// ```
111+
/// use godot::global::Error;
112+
///
113+
/// // Makeshift try block
114+
/// assert_eq!(
115+
/// Error::from_result((|| {
116+
/// Error::OK.err()?;
117+
/// Error::FAILED.err()?;
118+
/// Ok(())
119+
/// })()),
120+
/// Error::FAILED
121+
/// );
122+
/// ```
103123
pub fn from_result(result: Result<(), Self>) -> Self {
104124
match result {
105125
Ok(()) => Error::OK,
106126
Err(e) => e,
107127
}
108128
}
109129
}
110-
111-
/// Transparent `GodotConvert` implementation that uses `<Error as GodotConvert>`'s properties, so it uses the same representation.
112-
impl GodotConvert for Result<(), Error> {
113-
type Via = <Error as GodotConvert>::Via;
114-
115-
fn godot_shape() -> GodotShape {
116-
Error::godot_shape()
117-
}
118-
}
119-
120-
/// Shim that can turn incoming `Error` values into `Result<(), Error>`s, where `Error::OK` becomes `Ok(())`.
121-
impl FromGodot for Result<(), Error> {
122-
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError> {
123-
Ok(Error::try_from_godot(via)?.err())
124-
}
125-
}
126-
127-
/// Shim that turns outgoing `Result<(), Error>` values into `Error`s, where `Ok(())` becomes `Error::OK`.
128-
impl ToGodot for Result<(), Error> {
129-
type Pass = ByValue;
130-
131-
fn to_godot(&self) -> Self::Via {
132-
Error::from_result(*self).to_godot()
133-
}
134-
}

0 commit comments

Comments
 (0)