Use
Now that we've finished writing our gibbername crate, we'll demonstrate actually using it in a project. We will build gibbername-cli, a trivial wrapper around the library that lets you look up and register names on the command line. Using it willl look something like
gibbername-cli lookup tofnal-seh
hello world my dudes this is what's bound to the name lolYou can find a complete example in our GitHub repo.
Project setup
Let's start by creating a new binary crate:
cargo new gibbername-cli
cd gibbername-cliWe add melprot, melstructs, anyhow for error handling,argh for lightweight argument parsing, and futures-lite for bare-bones async support:
cargo add melprot melstructs anyhow argh futures-liteWe also need to add a dependency on Gibbername itself. This will be a "path" dependency to wherever, locally, you put the Gibbername crate:
[dependencies]
anyhow = "1.0.69"
argh = "0.1.10"
futures-lite = "1.12.0"
gibbername = { path = "../gibbername" }
melprot = "0.13.3"
melstructs = "0.3.2"Writing the main function
We write a basic scaffold that parses the arguments with argh:
Filling in the functionality
Now that we have a basic scaffold, filling in the functionality is incredibly easy:
Testing
We now have a complete program! We can test run it with cargo run:
Now, run the melwallet-cli command which will register our gibbername:
Finally, we can look up the binding we set in our register command using lookup:
Last updated