-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8293a4c
commit d6371ce
Showing
16 changed files
with
667 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
.*.swo | ||
/dist/ | ||
/target/ | ||
__pycache__/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use etcd_client::Client as RustClient; | ||
use pyo3::prelude::*; | ||
use pyo3::types::PyTuple; | ||
use pyo3_asyncio::tokio::future_into_py; | ||
use std::sync::Arc; | ||
use tokio::sync::Mutex; | ||
|
||
use crate::communicator::Communicator; | ||
use crate::error::Error; | ||
|
||
#[pyclass] | ||
#[derive(Clone)] | ||
pub struct Client { | ||
endpoints: Vec<String>, | ||
} | ||
|
||
#[pymethods] | ||
impl Client { | ||
#[new] | ||
fn new(endpoints: Vec<String>) -> Self { | ||
Self { endpoints } | ||
} | ||
|
||
fn connect(&self) -> Self { | ||
self.clone() | ||
} | ||
|
||
fn __aenter__<'a>(&'a self, py: Python<'a>) -> PyResult<&'a PyAny> { | ||
let endpoints = self.endpoints.clone(); | ||
future_into_py(py, async move { | ||
let result = RustClient::connect(endpoints, None).await; | ||
result | ||
.map(|client| Communicator(Arc::new(Mutex::new(client)))) | ||
.map_err(|e| Error(e).into()) | ||
}) | ||
} | ||
|
||
#[pyo3(signature = (*_args))] | ||
fn __aexit__<'a>(&'a self, py: Python<'a>, _args: &PyTuple) -> PyResult<&'a PyAny> { | ||
future_into_py(py, async move { Ok(()) }) | ||
} | ||
} |
Oops, something went wrong.