Skip to content

Commit

Permalink
fix protocol traits
Browse files Browse the repository at this point in the history
Annoyingly you still need to provide default impls for methods even
if they can't be called because the corresponding marker traits
aren't implemented.
  • Loading branch information
ohanar committed May 17, 2017
1 parent 49c3502 commit 3be2c9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/class/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ use conversion::{ToPyObject, FromPyObject};
/// Mapping interface
pub trait PyMappingProtocol: PythonObject {
fn __len__(&self, py: Python) -> Self::Result
where Self: PyMappingLenProtocol;
where Self: PyMappingLenProtocol
{ unimplemented!() }

fn __getitem__(&self, py: Python, key: Self::Key) -> Self::Result
where Self: PyMappingGetItemProtocol;
where Self: PyMappingGetItemProtocol
{ unimplemented!() }

fn __setitem__(&self, py: Python, key: Self::Key, value: Option<Self::Value>) -> Self::Result
where Self: PyMappingSetItemProtocol;
where Self: PyMappingSetItemProtocol
{ unimplemented!() }
}

// The following are a bunch of marker traits used to detect
Expand Down
26 changes: 17 additions & 9 deletions src/class/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,36 @@ use conversion::{ToPyObject, FromPyObject};
/// Sequence interface
pub trait PySequenceProtocol: PythonObject {
fn __len__(&self, py: Python) -> Self::Result
where Self: PySequenceLenProtocol;
where Self: PySequenceLenProtocol
{ unimplemented!() }

fn __getitem__(&self, py: Python, key: isize) -> Self::Result
where Self: PySequenceGetItemProtocol;
where Self: PySequenceGetItemProtocol
{ unimplemented!() }

fn __setitem__(&self, py: Python, key: isize, value: Option<Self::Value>) -> Self::Result
where Self: PySequenceSetItemProtocol;

where Self: PySequenceSetItemProtocol
{ unimplemented!() }

fn __contains__(&self, py: Python, value: Self::Value) -> Self::Result
where Self: PySequenceContainsProtocol;
where Self: PySequenceContainsProtocol
{ unimplemented!() }

fn __concat__(&self, py: Python, other: Self::Other) -> Self::Result
where Self: PySequenceConcatProtocol;
where Self: PySequenceConcatProtocol
{ unimplemented!() }

fn __repeat__(&self, py: Python, count: isize) -> Self::Result
where Self: PySequenceRepeatProtocol;
where Self: PySequenceRepeatProtocol
{ unimplemented!() }

fn __inplace_concat__(&self, py: Python, other: Self::Other) -> Self::Result
where Self: PySequenceInplaceConcatProtocol;
where Self: PySequenceInplaceConcatProtocol
{ unimplemented!() }

fn __inplace_repeat__(&self, py: Python, count: isize) -> Self::Result
where Self: PySequenceInplaceRepeatProtocol;
where Self: PySequenceInplaceRepeatProtocol
{ unimplemented!() }
}

// The following are a bunch of marker traits used to detect
Expand Down

0 comments on commit 3be2c9c

Please sign in to comment.