-
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
3923bf5
commit b6dc393
Showing
8 changed files
with
113 additions
and
10 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
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,48 @@ | ||
use etcd_client::{Compare, CompareOp}; | ||
use pyo3::prelude::*; | ||
use pyo3::pyclass::CompareOp as PyO3CompareOp; | ||
|
||
// #[derive(Clone)] | ||
// #[pyclass(name = "CompareOp")] | ||
// pub struct PyCompareOp(CompareOp); | ||
|
||
// #[pymethods] | ||
// impl PyCompareOp { | ||
// #[classattr] | ||
// const EQUAL: Self = Self(CompareOp::Equal); | ||
// #[classattr] | ||
// const GREATER: Self = Self(CompareOp::Greater); | ||
// #[classattr] | ||
// const LESS: Self = Self(CompareOp::Less); | ||
// #[classattr] | ||
// const NOT_EQUAL: Self = Self(CompareOp::NotEqual); | ||
|
||
// pub fn __repr__(&self) -> String { | ||
// match self.0 { | ||
// CompareOp::Equal => "EQUAL".to_owned(), | ||
// CompareOp::Greater => "GREATER".to_owned(), | ||
// CompareOp::Less => "LESS".to_owned(), | ||
// CompareOp::NotEqual => "NOT_EQUAL".to_owned(), | ||
// } | ||
// } | ||
|
||
// pub fn __richcmp__(&self, py: Python, rhs: &PyCompareOp, op: PyO3CompareOp) -> PyObject { | ||
// match op { | ||
// PyO3CompareOp::Eq => (self.0 == rhs.0).into_py(py), | ||
// PyO3CompareOp::Ne => (self.0 != rhs.0).into_py(py), | ||
// _ => py.NotImplemented(), | ||
// } | ||
// } | ||
// } | ||
|
||
#[derive(Clone)] | ||
#[pyclass(name = "Compare")] | ||
pub struct PyCompare(pub Compare); | ||
|
||
#[pymethods] | ||
impl PyCompare { | ||
// fn when(&self) { | ||
// self.inner. | ||
// } | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use etcd_client::{DeleteOptions, GetOptions, PutOptions, Txn, TxnOp}; | ||
use pyo3::prelude::*; | ||
|
||
use crate::compare::PyCompare; | ||
|
||
#[derive(Clone)] | ||
#[pyclass(name = "TxnOp")] | ||
pub struct PyTxnOp(TxnOp); | ||
|
||
#[pymethods] | ||
impl PyTxnOp { | ||
#[staticmethod] | ||
fn get(key: String) -> PyResult<Self> { | ||
let options = GetOptions::new(); | ||
Ok(PyTxnOp(TxnOp::get(key, Some(options)))) | ||
} | ||
#[staticmethod] | ||
fn put(key: String, value: String) -> PyResult<Self> { | ||
let options = PutOptions::new(); | ||
Ok(PyTxnOp(TxnOp::put(key, value, Some(options)))) | ||
} | ||
|
||
#[staticmethod] | ||
fn delete(key: String) -> PyResult<Self> { | ||
let options = DeleteOptions::new(); | ||
Ok(PyTxnOp(TxnOp::delete(key, Some(options)))) | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
#[pyclass(name = "Txn")] | ||
pub struct PyTxn(Txn); | ||
|
||
#[pymethods] | ||
impl PyTxn { | ||
fn when(&self, compares: Vec<PyCompare>) -> PyResult<Self> { | ||
let compares = compares.into_iter().map(|c| c.0).collect::<Vec<_>>(); | ||
Ok(PyTxn(self.0.clone().when(compares))) | ||
} | ||
|
||
fn and_then(&self, operations: Vec<PyTxnOp>) -> PyResult<Self> { | ||
let operations = operations.into_iter().map(|c| c.0).collect::<Vec<_>>(); | ||
Ok(PyTxn(self.0.clone().and_then(operations))) | ||
} | ||
|
||
fn or_else(&self, operations: Vec<PyTxnOp>) -> PyResult<Self> { | ||
let operations = operations.into_iter().map(|c| c.0).collect::<Vec<_>>(); | ||
Ok(PyTxn(self.0.clone().or_else(operations))) | ||
} | ||
} |
Empty file.
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 |
---|---|---|
|
@@ -109,7 +109,7 @@ impl PyWatch { | |
} | ||
|
||
result | ||
}, | ||
} | ||
None => return Err(PyStopAsyncIteration::new_err(())), | ||
}?; | ||
|
||
|