RustRover cargo-generate template: Axum + Vue 3 + TypeScript + Tailwind + sqlx
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

state.rs 681 B

12345678910111213141516171819202122232425262728293031323334353637
  1. use std::ops::Deref;
  2. use std::sync::Arc;
  3. use sqlx::PgPool;
  4. use crate::config::AppConfig;
  5. #[derive(Clone)]
  6. pub struct AppState(pub(crate) Arc<InnerState>);
  7. pub struct InnerState {
  8. pub config: AppConfig,
  9. pub db: PgPool,
  10. pub client: reqwest::Client,
  11. }
  12. impl AppState {
  13. pub fn new(config: AppConfig, db: PgPool, client: reqwest::Client) -> Self {
  14. Self(Arc::new(InnerState { config, db, client }))
  15. }
  16. pub fn db(&self) -> &PgPool {
  17. &self.0.db
  18. }
  19. pub fn config(&self) -> &AppConfig {
  20. &self.0.config
  21. }
  22. }
  23. impl Deref for AppState {
  24. type Target = InnerState;
  25. fn deref(&self) -> &Self::Target {
  26. &self.0
  27. }
  28. }