-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass operations as a mutable list (#15)
This more closely resembles the Rust API, and is a sufficiently ubiquitous concept in TaskChampion that I don't think it will be confusing for Python programmers.
- Loading branch information
Showing
13 changed files
with
549 additions
and
326 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
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,58 @@ | ||
use crate::Operation; | ||
use pyo3::{exceptions::PyIndexError, prelude::*}; | ||
use taskchampion::Operations as TCOperations; | ||
|
||
#[pyclass(sequence)] | ||
#[derive(PartialEq, Eq, Clone, Debug)] | ||
pub struct Operations(TCOperations); | ||
|
||
#[pymethods] | ||
impl Operations { | ||
#[new] | ||
pub fn new() -> Operations { | ||
Operations(TCOperations::new()) | ||
} | ||
|
||
pub fn append(&mut self, op: Operation) { | ||
self.0.push(op.into()); | ||
} | ||
|
||
pub fn __repr__(&self) -> String { | ||
format!("{:?}", self) | ||
} | ||
|
||
pub fn __len__(&self) -> usize { | ||
self.0.len() | ||
} | ||
|
||
pub fn __getitem__(&self, i: usize) -> PyResult<Operation> { | ||
if i >= self.0.len() { | ||
return Err(PyIndexError::new_err("Invalid operation index")); | ||
} | ||
Ok(Operation(self.0[i].clone())) | ||
} | ||
} | ||
|
||
impl AsRef<TCOperations> for Operations { | ||
fn as_ref(&self) -> &TCOperations { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl AsMut<TCOperations> for Operations { | ||
fn as_mut(&mut self) -> &mut TCOperations { | ||
&mut self.0 | ||
} | ||
} | ||
|
||
impl From<Operations> for TCOperations { | ||
fn from(val: Operations) -> Self { | ||
val.0 | ||
} | ||
} | ||
|
||
impl From<TCOperations> for Operations { | ||
fn from(val: TCOperations) -> Self { | ||
Operations(val) | ||
} | ||
} |
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
Oops, something went wrong.