From ede965411e6755b953f619a9a9a5bcfd9611503d Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Sat, 29 Jul 2023 11:26:00 +0200 Subject: [PATCH] Minor doc changes --- src/lib.rs | 1 + src/types/schema/user.rs | 3 +++ src/types/utils/jwt.rs | 6 ++++-- src/types/utils/snowflake.rs | 2 ++ src/voice.rs | 3 ++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8315a4d..6563bed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,7 @@ pub struct UrlBundle { } impl UrlBundle { + /// Creates a new UrlBundle from the relevant urls. pub fn new(api: String, wss: String, cdn: String) -> Self { Self { api: UrlBundle::parse_url(api), diff --git a/src/types/schema/user.rs b/src/types/schema/user.rs index c8cf5bb..9946e73 100644 --- a/src/types/schema/user.rs +++ b/src/types/schema/user.rs @@ -6,6 +6,7 @@ use crate::types::Snowflake; #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] +/// A schema used to modify a user. pub struct UserModifySchema { pub username: Option, pub avatar: Option, @@ -19,6 +20,8 @@ pub struct UserModifySchema { pub discriminator: Option, } +/// A schema used to create a private channel. +/// /// # Attributes: /// - recipients: The users to include in the private channel /// - access_tokens: The access tokens of users that have granted your app the `gdm.join` scope. Only usable for OAuth2 requests (which can only create group DMs). diff --git a/src/types/utils/jwt.rs b/src/types/utils/jwt.rs index c9f1aa5..951c58a 100644 --- a/src/types/utils/jwt.rs +++ b/src/types/utils/jwt.rs @@ -1,8 +1,8 @@ +#[allow(missing_docs)] +use crate::types::utils::Snowflake; use jsonwebtoken::{encode, EncodingKey, Header}; use serde::{Deserialize, Serialize}; -use crate::types::utils::Snowflake; - pub fn generate_token(id: &Snowflake, email: String, jwt_key: &str) -> String { let claims = Claims::new(&email, id); @@ -11,7 +11,9 @@ pub fn generate_token(id: &Snowflake, email: String, jwt_key: &str) -> String { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Claims { + /// When the token expires, unix epoch pub exp: i64, + /// When the token was issued pub iat: i64, pub email: String, pub id: String, diff --git a/src/types/utils/snowflake.rs b/src/types/utils/snowflake.rs index 81f3b5b..b34701a 100644 --- a/src/types/utils/snowflake.rs +++ b/src/types/utils/snowflake.rs @@ -18,6 +18,7 @@ const EPOCH: i64 = 1420070400000; pub struct Snowflake(u64); impl Snowflake { + /// Generates a snowflake for the current epoch. pub fn generate() -> Self { const WORKER_ID: u64 = 0; const PROCESS_ID: u64 = 1; @@ -31,6 +32,7 @@ impl Snowflake { Self(time as u64 | worker | process | increment) } + /// Returns the snowflake's timestamp pub fn timestamp(self) -> DateTime { Utc.timestamp_millis_opt((self.0 >> 22) as i64 + EPOCH) .unwrap() diff --git a/src/voice.rs b/src/voice.rs index 8b13789..c2fcaf2 100644 --- a/src/voice.rs +++ b/src/voice.rs @@ -1 +1,2 @@ - +//! Where the voice chat implementation will be, once it's finished. +//! For development on voice, see the feature/voice branch.