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
impl Rainier
Sourcepub fn new(base_path: impl Into<PathBuf>) -> Self
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.
Sourcepub fn with_events(self, register: impl FnOnce(&Dispatcher)) -> Self
pub fn with_events(self, register: impl FnOnce(&Dispatcher)) -> Self
Register event listeners.
Sourcepub fn with_middleware(self, register: impl FnOnce(&MiddlewareRegistry)) -> Self
pub fn with_middleware(self, register: impl FnOnce(&MiddlewareRegistry)) -> Self
Register middleware aliases and groups.
Sourcepub fn with_routes(self, declare: impl FnOnce(&mut Router)) -> Self
pub fn with_routes(self, declare: impl FnOnce(&mut Router)) -> Self
Declare routes.
Sourcepub fn with_views(self, engine: Arc<dyn ViewEngine>) -> Self
pub fn with_views(self, engine: Arc<dyn ViewEngine>) -> Self
Use a specific view engine. Defaults to a TemplateEngine over
<base>/resources/views.
Sourcepub fn with_database(self, database: Database) -> Self
pub fn with_database(self, database: Database) -> Self
Use this database.
Sourcepub fn with_queue(self, queue: QueueManager) -> Self
pub fn with_queue(self, queue: QueueManager) -> Self
Use this queue.
Sourcepub fn with_mailer(self, mailer: Mailer) -> Self
pub fn with_mailer(self, mailer: Mailer) -> Self
Use this mailer.
Sourcepub fn with_sessions(self, sessions: SessionManager) -> Self
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.
Sourcepub fn with_cache(self, cache: CacheManager) -> Self
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.
Sourcepub fn with_notifier(self, notifier: Notifier) -> Self
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)),
)Sourcepub fn with_broadcasting(self, broadcasting: Broadcasting) -> Self
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),
)))Sourcepub fn with_websockets(self, routes: WebSocketRoutes) -> Self
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)),
)Sourcepub fn with_instance<T: Send + Sync + 'static>(self, value: T) -> Self
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.
Sourcepub fn with_instance_arc<T: Send + Sync + 'static>(self, value: Arc<T>) -> Self
pub fn with_instance_arc<T: Send + Sync + 'static>(self, value: Arc<T>) -> Self
Bind something already shared, keeping your handle to it.
Sourcepub fn with_schedule(self, declare: impl FnOnce(&mut Schedule)) -> Self
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.
Sourcepub fn with_storage(self, storage: Storage) -> Self
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.
Sourcepub fn with_encryption(self, crypt: Encryption) -> Self
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.
Sourcepub fn with_provider(self, provider: impl ServiceProvider) -> Self
pub fn with_provider(self, provider: impl ServiceProvider) -> Self
Register a service provider.
Sourcepub fn without_facades(self) -> Self
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.
Sourcepub fn without_tracing(self) -> Self
pub fn without_tracing(self) -> Self
Do not install a tracing subscriber.
Sourcepub async fn boot(self) -> Result<Arc<Application>>
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§
impl !Freeze for Rainier
impl !RefUnwindSafe for Rainier
impl !Send for Rainier
impl !Sync for Rainier
impl !UnwindSafe for Rainier
impl Unpin for Rainier
impl UnsafeUnpin for Rainier
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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> ⓘ
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> ⓘ
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