pub struct EvidentSource { /* private fields */ }Expand description
The main entrypoint for connecting to an EvidentSource server.
EvidentSource manages the gRPC connection and provides methods for:
- Listing available databases (
DatabaseCatalogtrait) - Creating and deleting databases
- Connecting to a specific database for operations
§Example
ⓘ
use evidentsource_client::EvidentSource;
use evidentsource_core::domain::DatabaseName;
// Connect to the server
let es = EvidentSource::connect_to_server("http://localhost:50051").await?;
// List all databases
let mut databases = es.list_databases();
while let Some(name) = databases.next().await {
println!("Database: {}", name);
}
// Connect to a specific database
let db_name = DatabaseName::new("my-db")?;
let conn = es.connect(&db_name).await?;
// Use the connection for operations
let latest = conn.latest_database().await?;
println!("Latest revision: {}", latest.revision());Implementations§
Source§impl EvidentSource
impl EvidentSource
Sourcepub fn builder(addr: &str) -> EvidentSourceBuilder
pub fn builder(addr: &str) -> EvidentSourceBuilder
Sourcepub async fn connect_to_server(addr: &str) -> Result<Self, Error>
pub async fn connect_to_server(addr: &str) -> Result<Self, Error>
Sourcepub async fn connect_with_auth(
addr: &str,
credentials: Credentials,
) -> Result<Self, Error>
pub async fn connect_with_auth( addr: &str, credentials: Credentials, ) -> Result<Self, Error>
Connect to an EvidentSource server with authentication credentials.
§Arguments
addr- The server address (e.g.,http://localhost:50051orhttps://api.example.com)credentials- Authentication credentials (BearerToken, DevMode, or None)
§Examples
ⓘ
use evidentsource_client::{EvidentSource, Credentials, DevModeCredentials};
// With bearer token (production - requires TLS)
let es = EvidentSource::connect_with_auth(
"https://api.example.com:50051",
Credentials::BearerToken(my_jwt_token),
).await?;
// With DevMode credentials (local development)
let es = EvidentSource::connect_with_auth(
"http://localhost:50051",
Credentials::DevMode(
DevModeCredentials::new("dev-user@example.com")
.with_email("dev@example.com")
.with_display_name("Developer")
),
).await?;Sourcepub fn from_client(client: EvidentSourceClient) -> Self
pub fn from_client(client: EvidentSourceClient) -> Self
Create an EvidentSource instance from an existing client.
Sourcepub async fn connect(
&self,
database: &DatabaseName,
) -> Result<Connection, DatabaseError>
pub async fn connect( &self, database: &DatabaseName, ) -> Result<Connection, DatabaseError>
Connect to a specific database.
This returns a Connection that maintains a live subscription to
database updates and implements DatabaseProvider and DatabaseConnection.
§Arguments
database- The name of the database to connect to
§Example
ⓘ
let db_name = DatabaseName::new("my-db")?;
let conn = es.connect(&db_name).await?;Sourcepub fn client(&self) -> &EvidentSourceClient
pub fn client(&self) -> &EvidentSourceClient
Get a reference to the underlying gRPC client.
This provides access to low-level operations not exposed through the high-level API.
Sourcepub fn client_mut(&mut self) -> &mut EvidentSourceClient
pub fn client_mut(&mut self) -> &mut EvidentSourceClient
Get a mutable reference to the underlying gRPC client.
Trait Implementations§
Source§impl Clone for EvidentSource
impl Clone for EvidentSource
Source§fn clone(&self) -> EvidentSource
fn clone(&self) -> EvidentSource
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl DatabaseCatalog for EvidentSource
impl DatabaseCatalog for EvidentSource
Source§fn list_databases(&self) -> impl Stream<Item = DatabaseName>
fn list_databases(&self) -> impl Stream<Item = DatabaseName>
List all databases in the catalog.
Source§fn create_database(
&self,
name: DatabaseName,
) -> impl Future<Output = Result<Self::Identity, DatabaseError>>
fn create_database( &self, name: DatabaseName, ) -> impl Future<Output = Result<Self::Identity, DatabaseError>>
Create a new database with the given name.
Source§fn delete_database(
&self,
name: DatabaseName,
) -> impl Future<Output = Result<(), DatabaseError>>
fn delete_database( &self, name: DatabaseName, ) -> impl Future<Output = Result<(), DatabaseError>>
Delete a database by name.
Auto Trait Implementations§
impl !Freeze for EvidentSource
impl !RefUnwindSafe for EvidentSource
impl Send for EvidentSource
impl Sync for EvidentSource
impl Unpin for EvidentSource
impl !UnwindSafe for EvidentSource
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request