Struct vertigo::Driver

source ·
pub struct Driver { /* private fields */ }
Expand description

Main connection to vertigo facilities - dependencies and rendering client (the browser).

Implementations§

source§

impl Driver

source

pub fn cookie_get(&self, cname: &str) -> String

Gets a cookie by name

source

pub fn cookie_get_json(&self, cname: &str) -> JsJson

Gets a JsJson cookie by name

source

pub fn cookie_set(&self, cname: &str, cvalue: &str, expires_in: u64)

Sets a cookie under provided name

source

pub fn cookie_set_json(&self, cname: &str, cvalue: JsJson, expires_in: u64)

Sets a cookie under provided name

source

pub fn history_back(&self)

Go back in client’s (browser’s) history

source

pub fn set_interval(&self, time: u32, func: impl Fn() + 'static) -> DropResource

Make func fire every time seconds.

source

pub fn now(&self) -> Instant

Gets current value of monotonic clock.

source

pub fn request_get(&self, url: impl Into<String>) -> RequestBuilder

Create new RequestBuilder for GETs (more complex version of fetch)

source

pub fn request_post(&self, url: impl Into<String>) -> RequestBuilder

Create new RequestBuilder for POSTs (more complex version of fetch)

source

pub fn sleep(&self, time: u32) -> FutureBox<()>

source

pub fn get_random(&self, min: u32, max: u32) -> u32

source

pub fn get_random_from<K: Clone>(&self, list: &[K]) -> Option<K>

source

pub fn websocket<F: Fn(WebsocketMessage) + 'static>( &self, host: impl Into<String>, callback: F ) -> DropResource

Initiate a websocket connection. Provided callback should handle a single WebsocketMessage.

source

pub fn spawn(&self, future: impl Future<Output = ()> + 'static)

Spawn a future - thus allowing to fire async functions in, for example, event handler. Handy when fetching resources from internet.

source

pub fn transaction<R, F: FnOnce(&Context) -> R>(&self, func: F) -> R

Fire provided function in a way that all changes in dependency graph made by this function will trigger only one run of updates, just like the changes were done all at once.

source

pub fn dom_access(&self) -> DomAccess

source

pub fn on_after_transaction( &self, callback: impl Fn() + 'static ) -> DropResource

Function added for diagnostic purposes. It allows you to check whether a block with a transaction is missing somewhere.

source

pub fn is_browser(&self) -> bool

Return true if the code is executed client-side (in the browser).

use vertigo::{dom, get_driver};

let component = if get_driver().is_browser() {
    dom! { <div>"My dynamic component"</div> }
} else {
    dom! { <div>"Loading... (if not loaded check if JavaScript is enabled)"</div> }
};
source

pub fn is_server(&self) -> bool

source

pub fn env(&self, name: impl Into<String>) -> Option<String>

source

pub fn plains(&mut self, callback: impl Fn(&str) -> Option<String> + 'static)

Register handler that intercepts defined urls and generates plaintext responses during SSR.

Return None in the handler if regular HTML should be generated by the App.

use vertigo::get_driver;

get_driver().plains(|url| {
   if url == "/robots.txt" {
      Some("User-Agent: *\nDisallow: /search".to_string())
   } else {
      None
   }
});
source

pub fn try_get_plain(&self)

source

pub fn class_name_for(&mut self, css: &Css) -> String

Adds this CSS to manager producing a class name, which is returned

There shouldn’t be need to use it manually. It’s used by css! macro.

Trait Implementations§

source§

impl Clone for Driver

source§

fn clone(&self) -> Driver

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Driver

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Copy for Driver

Auto Trait Implementations§

§

impl Freeze for Driver

§

impl !RefUnwindSafe for Driver

§

impl !Send for Driver

§

impl !Sync for Driver

§

impl Unpin for Driver

§

impl !UnwindSafe for Driver

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.