Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
4kimov committed Jun 30, 2024
1 parent 8c7b28e commit ad38002
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 159 deletions.
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
too-many-arguments-threshold = 10
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: tests
on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Lint
run: |
rustfmt **/*.rs
cargo clippy --all -- -D warnings
- name: Install cargo check tools
run: |
cargo install --locked cargo-outdated || true
- name: Check
run: |
cargo outdated --exit-code 1
rm -rf ~/.cargo/advisory-db
- name: Test
run: cargo test --all
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# [Sqids PostgreSQL](https://sqids.org/postgresql)

[![Github Actions](https://img.shields.io/github/actions/workflow/status/sqids/sqids-postgresql/tests.yml)](https://github.com/sqids/sqids-postgresql/actions)

[Sqids](https://sqids.org/postgresql) (*pronounced "squids"*) is a small library that lets you **generate unique IDs from numbers**. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.

Features:
Expand Down
14 changes: 14 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
max_width = 100
comment_width = 100
hard_tabs = true
edition = "2021"
reorder_imports = true
imports_granularity = "Crate"
use_small_heuristics = "Max"
wrap_comments = true
binop_separator = "Back"
trailing_comma = "Vertical"
trailing_semicolon = true
use_field_init_shorthand = true
format_macro_bodies = true
format_code_in_doc_comments = true
30 changes: 15 additions & 15 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ use thiserror::Error;

#[derive(Error, Debug, Eq, PartialEq)]
pub enum Error {
#[error("Min length has to be between 0 and 255")]
MinLengthRange,
#[error("Numbers cannot be negative")]
NegativeNumbers,
#[error("Min length has to be between 0 and 255")]
MinLengthRange,
#[error("Numbers cannot be negative")]
NegativeNumbers,
}

pub enum PgError {
SqidsError(sqids::Error),
CustomError(Error),
SqidsError(sqids::Error),
CustomError(Error),
}

impl fmt::Display for PgError {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PgError::SqidsError(err) => error!("{}", err),
PgError::CustomError(err) => error!("{}", err),
}
}
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PgError::SqidsError(err) => error!("{}", err),
PgError::CustomError(err) => error!("{}", err),
}
}
}

impl From<sqids::Error> for PgError {
fn from(err: sqids::Error) -> Self {
PgError::SqidsError(err)
}
fn from(err: sqids::Error) -> Self {
PgError::SqidsError(err)
}
}
Loading

0 comments on commit ad38002

Please sign in to comment.