Skip to main content

Rainier

Struct Rainier 

Source
pub struct Rainier { /* private fields */ }
Expand description

Assembles an Application.

use rainier_framework::Rainier;

let app = Rainier::new(".")
    .with_routes(|router| {
        router.get("/", || async { "Hello from Rainier" });
    })
    .boot()
    .await?;

Implementations§

Source§

impl Rainier

Source

pub fn new(base_path: impl Into<PathBuf>) -> Self

Start from base_path, reading .env from it if there is one.

Infallible so the builder chain reads as one expression. A driver name the environment got wrong is held in deferred and returned from boot — the error still stops the application, it just does not force a ? into the middle of the chain.

Source

pub fn env(&self) -> &Env

The environment, for reading deployment values while building.

Source

pub fn config(&self) -> &Config

The configuration, for adding to it while building.

Source

pub fn configure(self, adjust: impl FnOnce(&Config)) -> Self

Adjust the configuration.

Source

pub fn with_events(self, register: impl FnOnce(&Dispatcher)) -> Self

Register event listeners.

Source

pub fn with_middleware(self, register: impl FnOnce(&MiddlewareRegistry)) -> Self

Register middleware aliases and groups.

Source

pub fn with_routes(self, declare: impl FnOnce(&mut Router)) -> Self

Declare routes.

Source

pub fn with_views(self, engine: Arc<dyn ViewEngine>) -> Self

Use a specific view engine. Defaults to a TemplateEngine over <base>/resources/views.

Source

pub fn with_database(self, database: Database) -> Self

Use this database.

Source

pub fn with_queue(self, queue: QueueManager) -> Self

Use this queue.

Source

pub fn with_mailer(self, mailer: Mailer) -> Self

Use this mailer.

Source

pub fn with_sessions(self, sessions: SessionManager) -> Self

Use this session store, and register the session middleware alias.

Without this, sessions default to an in-process store — right for development and wrong the moment there are two instances. See SessionManager.

Source

pub fn with_cache(self, cache: CacheManager) -> Self

Use this cache.

Defaults to an in-process one, which is right for development and wrong the moment a second instance exists — see CacheManager.

Source

pub fn with_notifier(self, notifier: Notifier) -> Self

Use these notification channels.

Without it, notifications go to the log — which delivers nothing, and is the right thing to have by accident: a misconfigured deployment logs them rather than emailing real people from a copy of production data.

ⓘ
Rainier::new(".").with_notifier(
    Notifier::new()
        .with(MailChannel::new(mailer))
        .with(DatabaseChannel::new(database)),
)
Source

pub fn with_broadcasting(self, broadcasting: Broadcasting) -> Self

Use this broadcast driver.

Without it, broadcasts go to the log — they reach no browser, which is the right accident to have: an application that has not configured a relay logs what it would have published instead of failing requests.

The channel table is not set here, because it is generic over your user model. Bind a ChannelRegistry<User> in a provider; until you do, every private channel is denied.

ⓘ
Rainier::new(".").with_broadcasting(Broadcasting::new(Arc::new(
    RedisBroadcaster::connect(&connector).await?.with_pusher_auth(auth),
)))
Source

pub fn with_websockets(self, routes: WebSocketRoutes) -> Self

Serve these WebSocket routes.

On the same port as HTTP: a socket connection begins as a GET asking to upgrade, so there is no second listener to start and nothing to run alongside anything.

ⓘ
Rainier::new(".").with_websockets(
    WebSocketRoutes::new().add("/ws/rooms/{room}", Chat::new(rooms)),
)
Source

pub fn with_instance<T: Send + Sync + 'static>(self, value: T) -> Self

Bind a value you already have.

The gap the typed with_* methods leave: an application often holds something the framework has never heard of — a Rooms registry, a feature-flag client, an HTTP client with a pool — and it needs to be resolvable without a provider whose whole body is one instance call.

A provider is still the right answer when the value has to be built from other bound services; this is for one that already exists.

Source

pub fn with_instance_arc<T: Send + Sync + 'static>(self, value: Arc<T>) -> Self

Bind something already shared, keeping your handle to it.

Source

pub fn with_schedule(self, declare: impl FnOnce(&mut Schedule)) -> Self

Declare the scheduled tasks.

ⓘ
Rainier::new(".").with_schedule(routes::console::schedule)

Bound in the container, so schedule:run and schedule:list find it.

Source

pub fn with_storage(self, storage: Storage) -> Self

Use this file storage.

Defaults to <base>/storage/app, so Storage::instance() works on a fresh clone without configuration.

Source

pub fn with_encryption(self, crypt: Encryption) -> Self

Use these keys for encryption and signing.

Defaults to APP_KEY from the environment. With neither, a random key is generated per boot — which works, and silently invalidates every encrypted value the last boot produced, so it warns.

Source

pub fn with_provider(self, provider: impl ServiceProvider) -> Self

Register a service provider.

Source

pub fn without_facades(self) -> Self

Do not install the facades’ global application.

Two applications in one process would otherwise fight over it — which is exactly what a test suite building an app per test does.

Source

pub fn without_tracing(self) -> Self

Do not install a tracing subscriber.

Source

pub async fn boot(self) -> Result<Arc<Application>>

Build and boot the application.

Compiling the router here is what makes an unknown middleware alias or a duplicate route name a boot failure rather than a surprise on the first request that hits it.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more