Fix WebpError trait impls missing #[cfg(feature = "server")]
This commit is contained in:
parent
263771e403
commit
b7220c28ef
46
src/cache.rs
46
src/cache.rs
@ -5,6 +5,7 @@ use std::sync::LazyLock;
|
|||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
use crate::models::post::{Post, PostStats, Tag};
|
use crate::models::post::{Post, PostStats, Tag};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -26,6 +27,7 @@ const TTL_TAG_POSTS: Duration = Duration::from_secs(120);
|
|||||||
// Cache Key Types
|
// Cache Key Types
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||||
pub enum CacheKey {
|
pub enum CacheKey {
|
||||||
PublishedPosts { page: i32, per_page: i32 },
|
PublishedPosts { page: i32, per_page: i32 },
|
||||||
@ -35,19 +37,7 @@ pub enum CacheKey {
|
|||||||
PostStats,
|
PostStats,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CacheKey {
|
|
||||||
pub(crate) fn as_string(&self) -> String {
|
|
||||||
match self {
|
|
||||||
CacheKey::PublishedPosts { page, per_page } => {
|
|
||||||
format!("posts:list:{}:{}", page, per_page)
|
|
||||||
}
|
|
||||||
CacheKey::AllTags => "tags:all".to_string(),
|
|
||||||
CacheKey::PostBySlug(slug) => format!("post:slug:{}", slug),
|
|
||||||
CacheKey::PostsByTag(tag) => format!("posts:tag:{}", tag),
|
|
||||||
CacheKey::PostStats => "posts:stats".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Cache Instances
|
// Cache Instances
|
||||||
@ -214,36 +204,6 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::models::post::PostStatus;
|
use crate::models::post::PostStatus;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn cache_key_published_posts_format() {
|
|
||||||
let key = CacheKey::PublishedPosts { page: 2, per_page: 10 };
|
|
||||||
assert_eq!(key.as_string(), "posts:list:2:10");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn cache_key_all_tags_format() {
|
|
||||||
let key = CacheKey::AllTags;
|
|
||||||
assert_eq!(key.as_string(), "tags:all");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn cache_key_post_by_slug_format() {
|
|
||||||
let key = CacheKey::PostBySlug("hello-world".to_string());
|
|
||||||
assert_eq!(key.as_string(), "post:slug:hello-world");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn cache_key_posts_by_tag_format() {
|
|
||||||
let key = CacheKey::PostsByTag("rust".to_string());
|
|
||||||
assert_eq!(key.as_string(), "posts:tag:rust");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn cache_key_post_stats_format() {
|
|
||||||
let key = CacheKey::PostStats;
|
|
||||||
assert_eq!(key.as_string(), "posts:stats");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cache_key_equality() {
|
fn cache_key_equality() {
|
||||||
let k1 = CacheKey::PublishedPosts { page: 1, per_page: 10 };
|
let k1 = CacheKey::PublishedPosts { page: 1, per_page: 10 };
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum WebpError {
|
pub enum WebpError {
|
||||||
Encode(String),
|
Encode(String),
|
||||||
Decode(String),
|
Decode(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl std::fmt::Display for WebpError {
|
impl std::fmt::Display for WebpError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
@ -16,6 +18,7 @@ impl std::fmt::Display for WebpError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl std::error::Error for WebpError {}
|
impl std::error::Error for WebpError {}
|
||||||
|
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user