into<S2> method

Err<S2, F> into<S2>()

Changes the Ok type to S2. This is usually used when "this" is known to be an Err and you want to return to the calling function, but the returning function's S type is different from this S type.

Example of proper use:

Result<int,String> someFunction1 () {...}

Result<String,String> someFunction2() {
  Result<int,String> result = someFunction1();
  if (result case Err()) {
    return result.into();
  }
...

Note how above, the S2 value is inferred by Dart, this is usually what be want rather than being explicit. Note: In Rust, "into" is handled by the "?" operator, but there is no equivalent in Dart.

Implementation

@pragma("vm:prefer-inline")
Err<S2, F> into<S2>() {
  return Err(err);
}