Skip to content

Commit 7ed3d02

Browse files
committed
Remove the result implementations and change documentation
It seems I forgot to clean up after myself
1 parent 46d907f commit 7ed3d02

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

godot-core/src/classes/manual_extensions.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
use crate::builtin::NodePath;
1616
use crate::classes::{Node, PackedScene};
1717
use crate::global::Error;
18-
use crate::meta::error::ConvertError;
19-
use crate::meta::{AsArg, ByValue, FromGodot, GodotConvert, GodotShape, ToGodot, arg_into_ref};
18+
use crate::meta::{AsArg, arg_into_ref};
2019
use crate::obj::{Gd, Inherits};
2120

2221
/// Manual extensions for the `Node` class.
@@ -91,44 +90,39 @@ impl Error {
9190
/// This is a convenience method that may be used to convert this type into one that can be used with the try operator (`?`)
9291
/// for easy short circuiting of Godot `Error`s.
9392
///
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.
93+
/// ```
94+
/// use godot::global::Error;
95+
///
96+
/// assert_eq!(Error::OK.err(), Ok(()));
97+
/// assert_eq!(Error::FAILED.err(), Err(Error::FAILED));
98+
/// ```
9699
pub fn err(self) -> Result<(), Self> {
97100
if self == Error::OK { Ok(()) } else { Err(self) }
98101
}
99102

100103
/// Creates an `Error` from a `Result<(), Error>`, the inverse of [`.err()`](Self::err).
101-
///
104+
///
102105
/// `Ok(())` becomes `Error::OK`, and `Err(e)` becomes `e`.
106+
///
107+
/// This can be used to implement "makeshift try blocks",
108+
/// or somehow else process the return value of a function that returns `Result<(), Error>`.
109+
/// ```
110+
/// use godot::global::Error;
111+
///
112+
/// // Makeshift try block
113+
/// assert_eq!(
114+
/// Error::from_result((|| {
115+
/// Error::OK.err()?;
116+
/// Error::FAILED.err()?;
117+
/// Ok(())
118+
/// })()),
119+
/// Error::FAILED
120+
/// );
121+
/// ```
103122
pub fn from_result(result: Result<(), Self>) -> Self {
104123
match result {
105124
Ok(()) => Error::OK,
106125
Err(e) => e,
107126
}
108127
}
109128
}
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)