CallbackSession

Struct CallbackSession 

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

A callback-based session for asynchronous operations

Implementations§

Source§

impl CallbackSession

Source

pub fn command<F>( &self, rql: &str, params: Option<Params>, callback: F, ) -> Result<String, Error>
where F: FnOnce(Result<CommandResult, Error>) + Send + 'static,

Send a command with callback

Examples found in repository?
examples/callback_ws.rs (lines 16-23)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9	// Connect to ReifyDB server
10	let client = Client::ws(("127.0.0.1", 8090))?;
11
12	// Create a callback session with authentication
13	let session = client.callback_session(Some("mysecrettoken".to_string()))?;
14
15	// Execute a command to create a table
16	let command_id = session.command(
17		"CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }",
18		None,
19		|result| match result {
20			Ok(data) => println!("Command executed: {} frames returned", data.frames.len()),
21			Err(e) => println!("Command failed: {}", e),
22		},
23	)?;
24	println!("Command sent with ID: {}", command_id);
25
26	// Execute a query
27	let query_id = session.query("MAP { x: 42, y: 'hello' }", None, |result| {
28		match result {
29			Ok(data) => {
30				println!("Query executed: {} frames returned", data.frames.len());
31				// Print first frame if available
32				if let Some(frame) = data.frames.first() {
33					println!("First frame:\n{}", frame);
34				}
35			}
36			Err(e) => println!("Query failed: {}", e),
37		}
38	})?;
39	println!("Query sent with ID: {}", query_id);
40
41	// Wait for callbacks to complete
42	thread::sleep(Duration::from_millis(500));
43
44	Ok(())
45}
Source

pub fn query<F>( &self, rql: &str, params: Option<Params>, callback: F, ) -> Result<String, Error>
where F: FnOnce(Result<QueryResult, Error>) + Send + 'static,

Send a query with callback

Examples found in repository?
examples/callback_ws.rs (lines 27-38)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9	// Connect to ReifyDB server
10	let client = Client::ws(("127.0.0.1", 8090))?;
11
12	// Create a callback session with authentication
13	let session = client.callback_session(Some("mysecrettoken".to_string()))?;
14
15	// Execute a command to create a table
16	let command_id = session.command(
17		"CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }",
18		None,
19		|result| match result {
20			Ok(data) => println!("Command executed: {} frames returned", data.frames.len()),
21			Err(e) => println!("Command failed: {}", e),
22		},
23	)?;
24	println!("Command sent with ID: {}", command_id);
25
26	// Execute a query
27	let query_id = session.query("MAP { x: 42, y: 'hello' }", None, |result| {
28		match result {
29			Ok(data) => {
30				println!("Query executed: {} frames returned", data.frames.len());
31				// Print first frame if available
32				if let Some(frame) = data.frames.first() {
33					println!("First frame:\n{}", frame);
34				}
35			}
36			Err(e) => println!("Query failed: {}", e),
37		}
38	})?;
39	println!("Query sent with ID: {}", query_id);
40
41	// Wait for callbacks to complete
42	thread::sleep(Duration::from_millis(500));
43
44	Ok(())
45}
Source

pub fn is_authenticated(&self) -> bool

Check if the session is authenticated

Source§

impl CallbackSession

Source

pub fn command_with_handler( &self, rql: &str, params: Option<Params>, handler: impl ResponseHandler + 'static, ) -> Result<String, Error>

Execute command with a response handler

Source

pub fn query_with_handler( &self, rql: &str, params: Option<Params>, handler: impl QueryHandler + 'static, ) -> Result<String, Error>

Execute query with a response handler

Trait Implementations§

Source§

impl Drop for CallbackSession

Source§

fn drop(&mut self)

Executes the destructor for this type. 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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.