Struct firebase_rs::Firebase
source · pub struct Firebase { /* private fields */ }
Implementations§
source§impl Firebase
impl Firebase
sourcepub fn new(uri: &str) -> Result<Self, UrlParseError>where
Self: Sized,
pub fn new(uri: &str) -> Result<Self, UrlParseError>where
Self: Sized,
use firebase_rs::Firebase;
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
sourcepub fn auth(uri: &str, auth_key: &str) -> Result<Self, UrlParseError>where
Self: Sized,
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();
sourcepub fn with_params(&self) -> Params
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;
sourcepub fn with_realtime_events(&self) -> Option<ServerEvents>
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;
sourcepub fn at(&self, path: &str) -> Self
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");
sourcepub fn get_uri(&self) -> String
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();
sourcepub async fn set<T>(&self, data: &T) -> Result<Response, RequestError>
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;
sourcepub async fn get_as_string(&self) -> Result<Response, RequestError>
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;
sourcepub async fn get<T>(&self) -> Result<T, RequestError>
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;
sourcepub async fn delete(&self) -> Result<Response, RequestError>
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;
sourcepub async fn update<T>(&self, data: &T) -> Result<Response, RequestError>
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§
Auto Trait Implementations§
impl Freeze for Firebase
impl RefUnwindSafe for Firebase
impl Send for Firebase
impl Sync for Firebase
impl Unpin for Firebase
impl UnwindSafe for Firebase
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> 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>
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