Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use swap_or_fill in Hero.move #84

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastx_programmability/framework/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "FastX"
version = "0.0.1"

[dependencies]
MoveStdlib = { git = "https://github.com/diem/diem.git", subdir="language/move-stdlib", rev = "56ab033cc403b489e891424a629e76f643d4fb6b" }
MoveStdlib = { git = "https://github.com/diem/diem.git", subdir="language/move-stdlib", rev = "5572eae5e35407f10316b473f95cb155a5e8d40b" }

[addresses]
Std = "0x1"
Expand Down
9 changes: 1 addition & 8 deletions fastx_programmability/framework/examples/Hero.move
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,7 @@ module Examples::Hero {
/// Add `new_sword` to the hero's inventory and return the old sword
/// (if any)
public fun equip_sword(hero: &mut Hero, new_sword: Sword): Option<Sword> {
// TODO: we should add a Option::swap_opt(&mut Option<T>, T): Option<T>
// that does this to the Move stdlib
if (Option::is_some(&hero.sword)) {
Option::some(Option::swap(&mut hero.sword, new_sword))
} else {
Option::fill(&mut hero.sword, new_sword);
Option::none<Sword>()
}
Option::swap_or_fill(&mut hero.sword, new_sword)
}

/// Disarm the hero by returning their sword.
Expand Down