Skip to main content

Client

Struct Client 

Source
pub struct Client<T = HttpTransport> { /* private fields */ }
Expand description

Configured client used to open Circle-backed SQLite databases.

Implementations§

Source§

impl Client<HttpTransport>

Source

pub fn from_default_config() -> Result<Self>

Load the default local config and construct a client with the HTTP transport.

This is fallible because it reads the configured octra-sqlite config file. Use Client::with_options when construction should be purely in-memory.

Examples found in repository?
examples/remilia-read-api/main.rs (line 15)
12fn main() -> AppResult<()> {
13    let addr = env::var("OCTRA_SQLITE_API_ADDR").unwrap_or_else(|_| "127.0.0.1:8787".to_string());
14    let database_name = env::var("OCTRA_SQLITE_DATABASE").unwrap_or_else(|_| "remilia".to_string());
15    let client = Client::from_default_config()?;
16    let database = client.database(database_name.clone())?;
17    let listener = TcpListener::bind(&addr)?;
18
19    eprintln!("listening on http://{addr}");
20    eprintln!("try: curl http://{addr}/collections/milady");
21
22    for stream in listener.incoming() {
23        match stream {
24            Ok(stream) => {
25                if let Err(error) = handle_connection(stream, &database, &database_name) {
26                    eprintln!("request error: {error}");
27                }
28            }
29            Err(error) => eprintln!("accept error: {error}"),
30        }
31    }
32
33    Ok(())
34}
Source

pub fn with_options(options: ClientOptions) -> Self

Construct a client from explicit options using the default HTTP transport.

Source§

impl<T: Transport> Client<T>

Source

pub fn with_transport(options: ClientOptions, transport: T) -> Self

Construct a client from explicit options and a custom transport.

Source

pub fn database(&self, target: impl Into<String>) -> Result<Database<T>>

Open a database by saved name, Circle ID, or oct:// URI.

Examples found in repository?
examples/remilia-read-api/main.rs (line 16)
12fn main() -> AppResult<()> {
13    let addr = env::var("OCTRA_SQLITE_API_ADDR").unwrap_or_else(|_| "127.0.0.1:8787".to_string());
14    let database_name = env::var("OCTRA_SQLITE_DATABASE").unwrap_or_else(|_| "remilia".to_string());
15    let client = Client::from_default_config()?;
16    let database = client.database(database_name.clone())?;
17    let listener = TcpListener::bind(&addr)?;
18
19    eprintln!("listening on http://{addr}");
20    eprintln!("try: curl http://{addr}/collections/milady");
21
22    for stream in listener.incoming() {
23        match stream {
24            Ok(stream) => {
25                if let Err(error) = handle_connection(stream, &database, &database_name) {
26                    eprintln!("request error: {error}");
27                }
28            }
29            Err(error) => eprintln!("accept error: {error}"),
30        }
31    }
32
33    Ok(())
34}

Trait Implementations§

Source§

impl<T: Clone> Clone for Client<T>

Source§

fn clone(&self) -> Client<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for Client<HttpTransport>

Available on crate feature http only.
Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for Client<T>

§

impl<T> RefUnwindSafe for Client<T>
where T: RefUnwindSafe,

§

impl<T> Send for Client<T>
where T: Sync + Send,

§

impl<T> Sync for Client<T>
where T: Sync + Send,

§

impl<T> Unpin for Client<T>

§

impl<T> UnsafeUnpin for Client<T>

§

impl<T> UnwindSafe for Client<T>
where T: RefUnwindSafe,

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

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.