expression
Return ownership when a consuming operation is rejected
A consuming method can return the original owner when validation fails. This lets a caller correct the data without making a backup clone. Use separate error information as needed in a larger API. The example uses distinct draft and submitted types, but does not implement external persistence. Expected result (NOT RUN): submitted: ready Common mistake: Discarding a valuable owned input on a recoverable failure without documenting that behavior. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
fn submit(self) -> Result<Submitted, Self>Working Example
Example Snippetrust
struct Draft(String);struct Submitted(String);impl Draft { fn submit(self) -> Result<Submitted, Self> { if self.0.trim().is_empty() { Err(self) } else { Ok(Submitted(self.0)) } }}fn main() { let draft = Draft(String::new()); let mut recovered = match draft.submit() { Err(d) => d, Ok(_) => unreachable!() }; recovered.0.push_str("ready"); match recovered.submit() { Ok(item) => println!("submitted: {}", item.0), Err(_) => unreachable!(), }}