Skip to content

Commit

Permalink
Title: Fix README examples
Browse files Browse the repository at this point in the history
Body: Update README examples to correct version / codes
  • Loading branch information
Alastair-smith2 committed Nov 12, 2022
1 parent 4b10cfe commit 75b1def
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rusty_hyrule_compendium"
version = "0.1.2"
version = "0.1.3"
description = "A rust library for the Hyrule Compendium API"
repository = "https://github.com/Alastair-smith2/rusty_hyrule_compendium"
edition = "2021"
Expand Down
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Start by adding the following snippet to your `Cargo.toml`

```toml
[dependencies]
rusty_hyrule_compendium = "0.1.0"
rusty_hyrule_compendium = "0.1.3"
```

To use this library, you'll need to instantiate the Compendium client. `CompendiumClient::default();` preconfigures the underlying HTTP client and API url with sensible values.
Expand Down Expand Up @@ -51,12 +51,22 @@ Each of the resources (see below for comprehensive list) have a [struct](https:/
Furthermore it's possbile to request all of the above by category but pattern matching is required to get the entries.

```rust
let result = client.category(CompendiumCategory::Treasure)?;
match result {
CategoryResult::Treasure(treasure) => {
// Do something with the Vec<TreasureEntry>
use rusty_hyrule_compendium::blocking::{CompendiumApiClient, CompendiumClient};
use rusty_hyrule_compendium::domain::inputs::CompendiumCategory;
use rusty_hyrule_compendium::domain::responses::CategoryResult;
use rusty_hyrule_compendium::Result;

fn main() -> Result<()> {
// Preconfigured client using v2 of the API
let client = CompendiumClient::default();
let result = client.category(CompendiumCategory::Treasure)?;
match result {
CategoryResult::Treasure(treasure) => {
// Do something with the Vec<TreasureEntry>
}
_ => { /* Return some form of error, unexpected scenario */}
}
_ => panic!("Unexpected result while search for treasure category"),
Ok(())
}
```

Expand All @@ -67,9 +77,17 @@ It's also possible to get all entries by the `.all_entries()` method
E.g.

```rust
let all_entries = client.all_entries()?;
// Get all creature entries that are food specific, &Vec<CreatureEntry> type
let food_creatures = all_entries.creatures().food();
use rusty_hyrule_compendium::blocking::{CompendiumApiClient, CompendiumClient};
use rusty_hyrule_compendium::Result;

fn main() -> Result<()> {
// Preconfigured client using v2 of the API
let client = CompendiumClient::default();
let all_entries = client.all_entries()?;
// Get all creature entries that are food specific, &Vec<CreatureEntry> type
let food_creatures = all_entries.creatures().food();
Ok(())
}
```

## Available resources from the API
Expand Down

0 comments on commit 75b1def

Please sign in to comment.