pub enum NodeOutput<T> {
SoftFail,
Ok(T),
}Expand description
Represents the outcome of a node execution, with support for soft failures.
§Examples
use node_flow::node::NodeOutput;
let success: NodeOutput<i32> = NodeOutput::Ok(42);
let failure: NodeOutput<i32> = NodeOutput::SoftFail;
assert_eq!(success.ok(), Some(42));
assert_eq!(failure.ok(), None);Variants§
SoftFail
Indicates that the node failed in a non-critical way and produced no output.
This is distinct from a hard failure (error) and may simply mean that input conditions were not met.
Ok(T)
Indicates that the node successfully produced a value of type T.
Implementations§
Source§impl<T> NodeOutput<T>
impl<T> NodeOutput<T>
Sourcepub fn ok(self) -> Option<T>
pub fn ok(self) -> Option<T>
Converts NodeOutput<T> into an Option<T>.
- Returns
Some(T)if the output isNodeOutput::Ok. - Returns
Noneif the output isNodeOutput::SoftFail.
§Examples
use node_flow::node::NodeOutput;
let output = NodeOutput::Ok(5);
assert_eq!(output.ok(), Some(5));
let failed = NodeOutput::<i32>::SoftFail;
assert_eq!(failed.ok(), None);Sourcepub fn ok_or<E>(self, err: E) -> Result<T, E>
pub fn ok_or<E>(self, err: E) -> Result<T, E>
Converts NodeOutput<T> into a Result<T, E>,
using a provided error value if soft-failed.
- Returns
Ok(T)if the output isNodeOutput::Ok. - Returns
Err(err)if the output isNodeOutput::SoftFail.
§Errors
Returns the provided err value if the node soft-failed.
§Examples
use node_flow::node::NodeOutput;
let ok: Result<i32, &str> = NodeOutput::Ok(42).ok_or("no value");
assert_eq!(ok, Ok(42));
let soft_fail: Result<i32, &str> = NodeOutput::SoftFail.ok_or("no value");
assert_eq!(soft_fail, Err("no value"));Sourcepub fn ok_or_else<E>(self, err: impl Fn() -> E) -> Result<T, E>
pub fn ok_or_else<E>(self, err: impl Fn() -> E) -> Result<T, E>
Converts NodeOutput<T> into a Result<T, E>,
lazily computing the error value if soft-failed.
- Returns
Ok(T)if the output isNodeOutput::Ok. - Calls
err()and returnsErr(err())if the output isNodeOutput::SoftFail.
This is the lazy variant of NodeOutput::ok_or, avoiding unnecessary error construction
when the node succeeds.
§Errors
Calls the provided closure to produce an error if the node soft-failed.
§Examples
use node_flow::node::NodeOutput;
let ok: Result<i32, String> = NodeOutput::Ok(10).ok_or_else(|| "soft fail".to_string());
assert_eq!(ok, Ok(10));
let soft_fail: Result<i32, String> = NodeOutput::SoftFail.ok_or_else(|| "soft fail".to_string());
assert_eq!(soft_fail, Err("soft fail".to_string()));