Skip to content

Commit

Permalink
feat: add PuzzlePart conversion from i64
Browse files Browse the repository at this point in the history
  • Loading branch information
scarvalhojr committed Jan 11, 2023
1 parent 19c65f8 commit e10b828
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aoc-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
8 changes: 4 additions & 4 deletions aoc-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions aoc-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[package]
name = "aoc-client"
description = "Advent of Code client library"
version = "0.1.0"
version = "0.1.1"
authors = ["Sergio de Carvalho <[email protected]>"]
categories = ["command-line-utilities"]
edition = "2021"
repository = "https://github.com/scarvalhojr/aoc-cli"
documentation = "https://docs.rs/crate/aoc-cli/latest"
documentation = "https://docs.rs/crate/aoc-client/latest"
readme = "README.md"
license = "MIT"

Expand Down
15 changes: 13 additions & 2 deletions aoc-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ tool but can also be integrated into other projects.

Add the following dependency to your Rust project (in `Cargo.toml`):

```
```toml
[dependencies]
aoc-client = "0.1"
```

Create a `AocClient` instance and call its methods:

```Rust
```rust
use aoc_client::{AocClient, AocResult};

fn main() -> AocResult<()> {
Expand All @@ -44,3 +44,14 @@ fn main() -> AocResult<()> {
Ok(())
}
```

## Contribute 🦌

Feedback and pull requests are welcome. Please see [CONTRIBUTING](..\CONTRIBUTING.md)
for guidelines and ideas.

## Support Advent of Code 🎁

Advent of Code is a free online Advent calendar of small programming puzzles
created by [Eric Wastl](http://was.tl/) and maintained by volunteers. Please
consider [supporting their work](https://adventofcode.com/support).
12 changes: 12 additions & 0 deletions aoc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,15 @@ impl TryFrom<&str> for PuzzlePart {
}
}
}

impl TryFrom<i64> for PuzzlePart {
type Error = AocError;

fn try_from(n: i64) -> Result<Self, Self::Error> {
match n {
1 => Ok(Self::PartOne),
2 => Ok(Self::PartTwo),
_ => Err(AocError::InvalidPuzzlePart),
}
}
}

0 comments on commit e10b828

Please sign in to comment.