Skip to content

Commit

Permalink
feat(app-state): added 'helpers()' helper func to easily acquire stru…
Browse files Browse the repository at this point in the history
…ct of helpers
  • Loading branch information
Ahmard committed Aug 20, 2024
1 parent a4b525d commit 97f8e2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Medullah Changelog
medullah-web changelog file

## 0.14.6 (2024-08-20)
* feat(http): added separate serializer & deserializer
* feat(app-state): added 'helpers()' helper func to easily acquire struct of helpers

## 0.14.5 (2024-08-18)
* bump: upgraded packages to their latest versions

Expand Down
12 changes: 8 additions & 4 deletions src/helpers/once_lock.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#[allow(unused_imports)]
use std::sync::{Arc, OnceLock};

#[cfg(feature = "feat-database")]
use diesel::r2d2::ConnectionManager;
#[cfg(feature = "feat-database")]
use diesel::PgConnection;
#[cfg(feature = "feat-database")]
use diesel::r2d2::ConnectionManager;

use crate::app_state::MedullahState;
use crate::app_state::{AppHelpers, MedullahState};
#[cfg(feature = "feat-database")]
use crate::database::DatabaseConnectionHelper;
use crate::MEDULLAH;
#[cfg(feature = "feat-redis")]
use crate::services::cache_service::CacheService;
use crate::MEDULLAH;

pub trait OnceLockHelper<'a> {
fn app(&self) -> &'a MedullahState {
MEDULLAH.get().unwrap()
}

fn helpers(&self) -> &AppHelpers {
&MEDULLAH.get().unwrap().helpers
}

fn front_url(&self, url: &str) -> String {
self.app().frontend(url)
}
Expand Down

0 comments on commit 97f8e2e

Please sign in to comment.