Skip to content

Commit

Permalink
Add ThinString for smaller structs
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy committed Sep 7, 2024
1 parent 0b2f8ef commit bda44f7
Show file tree
Hide file tree
Showing 18 changed files with 610 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rend = { git = "https://github.com/rkyv/rend" }
snowflake = { git = "https://github.com/Lantern-chat/snowflake", features = ["timestamp"] }
timestamp = { package = "iso8601-timestamp", version = "0.3.0-beta.1" }

rkyv = { version = "0.8.0-rc.1", optional = true, features = ["bytecheck", "smol_str_03", "thin-vec", "triomphe"] }
rkyv = { version = "0.8.0-rc.1", optional = true, features = ["bytecheck", "smol_str-0_3", "thin-vec-0_2", "triomphe-0_1"] }
rkyv_rpc = { git = "https://github.com/Lantern-chat/rkyv_rpc", optional = true }

serde = { version = "1", features = ["derive", "rc"] }
Expand Down
2 changes: 1 addition & 1 deletion src/api/commands/party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ command! {

#[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
pub description: Option<SmolStr>,
pub description: Option<ThinString>,

#[serde(default)]
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
Expand Down
9 changes: 7 additions & 2 deletions src/api/commands/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ decl_enum! {
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
archive(check_bytes)
)]
pub struct Added2FA {
/// URL to be display as a QR code and added to an authenticator app
pub url: String,
/// Backup codes to be stored in a safe place
pub backup: Vec<String>,
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::bad_bit_mask)]

extern crate alloc;

#[cfg(all(feature = "typed-builder", feature = "bon"))]
compile_error!("'typed-builder' and 'bon' features are mutually exclusive");

Expand Down
4 changes: 3 additions & 1 deletion src/models/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::*;

pub type HCaptchaSiteKey = FixedStr<36>;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(
Expand All @@ -8,7 +10,7 @@ use super::*;
archive(check_bytes)
)]
pub struct ServerConfig {
pub hcaptcha_sitekey: FixedStr<36>,
pub hcaptcha_sitekey: HCaptchaSiteKey,

/// CDN Domain
pub cdn: SmolStr,
Expand Down
2 changes: 1 addition & 1 deletion src/models/embed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub type EmbedWithExpire = (timestamp::Timestamp, Embed);

#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
Expand Down
Loading

0 comments on commit bda44f7

Please sign in to comment.