Struct firebase_rs::Firebase

source ·
pub struct Firebase { /* private fields */ }

Implementations§

source§

impl Firebase

source

pub fn new(uri: &str) -> Result<Self, UrlParseError>
where Self: Sized,

use firebase_rs::Firebase;

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
source

pub fn auth(uri: &str, auth_key: &str) -> Result<Self, UrlParseError>
where Self: Sized,

const URI: &str = "...";
const AUTH_KEY: &str = "...";

use firebase_rs::Firebase;

let firebase = Firebase::auth("https://myfirebase.firebaseio.com", AUTH_KEY).unwrap();
source

pub fn with_params(&self) -> Params

use firebase_rs::Firebase;

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().with_params().start_at(1).order_by("name").equal_to(5).finish();
let result = firebase.get::<String>().await;
source

pub fn with_realtime_events(&self) -> Option<ServerEvents>

To use simple interface with synchronous callbacks, pair with .listen():

use firebase_rs::Firebase;
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let stream = firebase.with_realtime_events().unwrap();
stream.listen(|event_type, data| {
                    println!("{:?} {:?}" ,event_type, data);
                }, |err| println!("{:?}" ,err), false).await;

To use streaming interface for async code, pair with .stream():

use firebase_rs::Firebase;
use futures_util::StreamExt;

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let stream = firebase.with_realtime_events()
             .unwrap()
             .stream(true);
stream.for_each(|event| {
          match event {
              Ok((event_type, maybe_data)) => println!("{:?} {:?}" ,event_type, maybe_data),
              Err(err) => println!("{:?}" ,err),
          }
          futures_util::future::ready(())
       }).await;
source

pub fn at(&self, path: &str) -> Self

use firebase_rs::Firebase;

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users").at("USER_ID").at("f69111a8a5258c15286d3d0bd4688c55");
source

pub fn get_uri(&self) -> String

use firebase_rs::Firebase;

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let uri = firebase.get_uri();
source

pub async fn set<T>(&self, data: &T) -> Result<Response, RequestError>

use firebase_rs::Firebase;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct User {
   name: String
}

let user = User { name: String::default() };
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let users = firebase.set(&user).await;
source

pub async fn get_as_string(&self) -> Result<Response, RequestError>

use std::collections::HashMap;
use firebase_rs::Firebase;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct User {
   name: String
}

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let users = firebase.get::<HashMap<String, User>>().await;
source

pub async fn get<T>(&self) -> Result<T, RequestError>

use std::collections::HashMap;
use firebase_rs::Firebase;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct User {
    name: String
}

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users").at("USER_ID");
let user = firebase.get::<User>().await;

 // OR

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let user = firebase.get::<HashMap<String, User>>().await;
source

pub async fn delete(&self) -> Result<Response, RequestError>

use firebase_rs::Firebase;

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users").at("USER_ID");
firebase.delete().await;
source

pub async fn update<T>(&self, data: &T) -> Result<Response, RequestError>

use firebase_rs::Firebase;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct User {
    name: String
}

let user = User { name: String::default() };
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users").at("USER_ID");
let users = firebase.update(&user).await;

Trait Implementations§

source§

impl Debug for Firebase

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<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<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.
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