Skip to content

Commit 6908d89

Browse files
authored
add default impl (#272)
1 parent 5c519b4 commit 6908d89

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

crates/iota-transaction-builder/src/builder/named_results.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,31 @@ use crate::{builder::TransactionBuildData, unresolved::Argument};
66
/// A trait that defines a named result, either a string or nothing.
77
pub trait NamedResult {
88
/// Get the named result argument.
9-
fn named_result(&self, ptb: &mut TransactionBuildData) -> Argument;
9+
fn named_result(&self, ptb: &mut TransactionBuildData) -> Argument {
10+
Argument::Result((ptb.commands.len() - 1) as _)
11+
}
1012

1113
/// Push the named result to the PTB.
1214
fn push_named_result(self, arg: Argument, ptb: &mut TransactionBuildData);
1315
}
1416

1517
impl NamedResult for () {
16-
fn named_result(&self, ptb: &mut TransactionBuildData) -> Argument {
17-
Argument::Result((ptb.commands.len() - 1) as _)
18-
}
19-
2018
fn push_named_result(self, _: Argument, _: &mut TransactionBuildData) {}
2119
}
2220

2321
impl NamedResult for &str {
24-
fn named_result(&self, ptb: &mut TransactionBuildData) -> Argument {
25-
Argument::Result((ptb.commands.len() - 1) as _)
26-
}
27-
2822
fn push_named_result(self, arg: Argument, ptb: &mut TransactionBuildData) {
2923
ptb.named_results.insert(self.to_owned(), arg);
3024
}
3125
}
3226

3327
impl NamedResult for String {
34-
fn named_result(&self, ptb: &mut TransactionBuildData) -> Argument {
35-
Argument::Result((ptb.commands.len() - 1) as _)
36-
}
37-
3828
fn push_named_result(self, arg: Argument, ptb: &mut TransactionBuildData) {
3929
ptb.named_results.insert(self.to_owned(), arg);
4030
}
4131
}
4232

4333
impl<T: NamedResult> NamedResult for Option<T> {
44-
fn named_result(&self, ptb: &mut TransactionBuildData) -> Argument {
45-
Argument::Result((ptb.commands.len() - 1) as _)
46-
}
47-
4834
fn push_named_result(self, arg: Argument, ptb: &mut TransactionBuildData) {
4935
if let Some(s) = self {
5036
s.push_named_result(arg, ptb)

0 commit comments

Comments
 (0)