Skip to content

Commit

Permalink
feat(lib): add lib
Browse files Browse the repository at this point in the history
  • Loading branch information
apogeeoak committed Mar 18, 2023
1 parent 8b83edb commit 7570c13
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Rust

on:
push:
branches: [main]
tags: 'v*'
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always
# Fail on all warnings.
RUSTFLAGS: '-Dwarnings'

jobs:
build:
name: Build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Toolchain versions
run: |
rustc --version
cargo --version
- name: Build
run: cargo build --release --all-targets --all-features --verbose

- name: Clippy
run: cargo clippy --release --all-targets --all-features --verbose

- name: Test
run: cargo test --release --all-targets --all-features

# Create release only for tag commit.
## General
- name: General release artifacts
if: ${{ startsWith(github.ref, 'refs/tags') && matrix.os == 'ubuntu-latest' }}
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: collection.toml

## Ubuntu
- name: Prepare Ubuntu release
if: ${{ startsWith(github.ref, 'refs/tags') && matrix.os == 'ubuntu-latest' }}
run: strip target/release/collection

- name: Create Ubuntu release
if: ${{ startsWith(github.ref, 'refs/tags') && matrix.os == 'ubuntu-latest' }}
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: target/release/collection

## Windows
- name: Create Windows release
if: ${{ startsWith(github.ref, 'refs/tags') && matrix.os == 'windows-latest' }}
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: target/release/collection.exe
212 changes: 212 additions & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "collection"
version = "0.1.0"
edition = "2021"

[dependencies]
rand = "0.8"
serde = {version = "1.0", features = ["derive"]}
toml = "0.7"
61 changes: 61 additions & 0 deletions collection.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
title = "Title"

[[collections]]
label = "Items"
width = 10
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 0
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 1
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 2
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 3
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 4
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 5
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 6
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 7
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 8
items = ["One", "Two", "Three", "Four", "Five", "Six", "12345678901234567890", "A", "Be"]

[[collections]]
label = "Items"
width = 10
items = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]

[[collections]]
label = "Items"
width = 10
items = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven"]
9 changes: 9 additions & 0 deletions src/config/collection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use serde::Deserialize;

// Struct to hold the [[collections]] table.
#[derive(Debug, Deserialize)]
pub struct Collection {
pub label: String,
pub width: u8,
pub items: Vec<String>,
}
26 changes: 26 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pub mod collection;

use serde::Deserialize;
use std::error::Error;
use std::fs;

use collection::Collection;

// Top level struct to hold entire input configuration.
#[derive(Debug, Deserialize)]
pub struct Config {
pub title: String,
pub collections: Vec<Collection>,
}

impl Config {
pub fn read() -> Result<Config, Box<dyn Error>> {
let filename = "collection.toml";

let contents = fs::read_to_string(filename).map_err(|err| format!("Unable to read file '{}'. Error: {}", filename, err))?;

let input: Config = toml::from_str(&contents).map_err(|err| format!("Unable to load data from '{}'. Error: {}", filename, err))?;

Ok(input)
}
}
Loading

0 comments on commit 7570c13

Please # to comment.