Skip to content

Commit e6b5337

Browse files
authored
Add example to documentation
1 parent c87245c commit e6b5337

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1-
//! The official Rust implementation of the RANDEVU algorithm
1+
//! The official Rust implementation of the [RANDEVU](https://github.com/TypicalHog/randevu) algorithm
2+
//!
3+
//! # Example
4+
//! ```rust
5+
//! use randevu::{rdv, utc_date_with_offset};
6+
//!
7+
//! fn main() {
8+
//! let object = "THE_SIMPSONS";
9+
//! let date = utc_date_with_offset(0);
10+
//! let rdv = rdv(object, &date);
11+
//!
12+
//! println!("Object {} has RDV{} today", object, rdv);
13+
//! }
14+
//! ```
215
316
use blake3;
417
use chrono::{Duration, Utc};
518

6-
/// Returns current UTC date (String) in ISO 8601 format, with an offset (i64) in days
19+
/// Returns current UTC DATE `String` in ISO 8601 format (YYYY-MM-DD), with an OFFSET `i64` in days
720
pub fn utc_date_with_offset(offset: i64) -> String {
821
(Utc::now() + Duration::days(offset))
922
.format("%Y-%m-%d")
1023
.to_string()
1124
}
1225

13-
/// Returns RDV level (u32) for an object (&str) on a specific date (&str)
26+
/// Returns RDV level `u32` for an OBJECT `&str` on a specific DATE `&str`
1427
///
15-
/// RDV = number of leading zero bits in blake3(blake3(OBJECT) || blake3(DATE))
28+
/// **RDV = number of leading zero bits in blake3(blake3(OBJECT) || blake3(DATE))**
1629
pub fn rdv(object: &str, date: &str) -> u32 {
1730
let mut hasher = blake3::Hasher::new();
1831
hasher.update(blake3::hash(object.as_bytes()).as_bytes());

0 commit comments

Comments
 (0)