Skip to content

Commit

Permalink
Merge branch 'main' into vrongmeal/upgrade-proto
Browse files Browse the repository at this point in the history
  • Loading branch information
vrongmeal authored Dec 13, 2024
2 parents 751c613 + ccb496a commit d1d6d14
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ jobs:
with:
crate: cargo-sort
version: "^1.0"
- name: check proto build up-to-date
run: |
cargo build --features prost-build
git diff --exit-code src/api.rs && echo "Up-to-date" || {
echo "Not up-to-date"
exit 1
}
- name: check documentation
env:
RUSTDOCFLAGS: -D warnings
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ hyper = "1.5.0"
hyper-util = "0.1.10"
prost = "0.13.3"
prost-types = "0.13.3"
rand = "0.8.5"
regex = "1.11.1"
secrecy = "0.8.0"
sync_docs = "0.2.0"
Expand Down
11 changes: 11 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{ops::Deref, str::FromStr, sync::OnceLock, time::Duration};

use bytes::Bytes;
use rand::{distributions::Uniform, Rng};
use regex::Regex;
use sync_docs::sync_docs;

Expand Down Expand Up @@ -849,6 +850,16 @@ impl FencingToken {
Ok(Self(bytes))
}
}

/// Generate a random fencing token with `n` bytes.
pub fn generate(n: usize) -> Result<Self, ConvertError> {
Self::new(
rand::thread_rng()
.sample_iter(&Uniform::new_inclusive(0, u8::MAX))
.take(n)
.collect::<Bytes>(),
)
}
}

impl AsRef<Bytes> for FencingToken {
Expand Down

0 comments on commit d1d6d14

Please sign in to comment.