pub struct Env {
pub db_url: String,
pub token_secret: String,
pub origin: String,
}Expand description
Environment configuration for the application.
Loads required configuration from environment variables at startup.
All variables must be present or the application will panic during Env::load.
Used by AppState for configuring JWT signing and CORS.
§Fields
db_url: PostgreSQL database connection URLtoken_secret: Secret key used to sign and verifyClaimsin JWT tokensorigin: Frontend origin URL for CORS policy configuration
§Required Environment Variables
DATABASE_URL: PostgreSQL connection string (e.g.,postgresql://user:pass@localhost/dbname)TOKEN_SECRET: Secret key for JWT token signing (use a strong random string in production)ORIGIN: Frontend URL for CORS (e.g.,http://localhost:8080)
Fields§
§db_url: StringPostgreSQL database connection URL
token_secret: StringSecret key used to sign and verify JWT tokens
origin: StringFrontend origin URL for CORS policy
Implementations§
Source§impl Env
impl Env
Sourcepub fn load() -> Env
pub fn load() -> Env
Loads environment configuration from system environment variables.
Reads DATABASE_URL, TOKEN_SECRET, and ORIGIN from the environment and returns
a configured Env instance. Used during server initialization in the main function.
§Panics
If any required variable is missing (DATABASE_URL, TOKEN_SECRET, or ORIGIN).
§Example
ⓘ
let env = Env::load();
// Environment must have DATABASE_URL, TOKEN_SECRET, and ORIGIN set
let app_state = AppState {
db: pool,
env,
};Trait Implementations§
Auto Trait Implementations§
impl Freeze for Env
impl RefUnwindSafe for Env
impl Send for Env
impl Sync for Env
impl Unpin for Env
impl UnwindSafe for Env
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more