Skip to content

Commit

Permalink
Remove nightly feature
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Dec 27, 2020
1 parent 5a92708 commit 5a8ef29
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 104 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ rustversion = "1.0"
default = ["macros"]
macros = ["ctor", "indoc", "inventory", "paste", "pyo3cls", "unindent"]

# Supports arrays of arbitrary size
const-generics = []

# Optimizes PyObject to Vec conversion and so on.
nightly = []

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg_attr(feature = "const-generics", feature(min_const_generics))]
#![cfg_attr(feature = "nightly", allow(incomplete_features))]
#![cfg_attr(feature = "nightly", feature(specialization))]
#![allow(clippy::missing_safety_doc)] // FIXME (#698)

Expand Down
23 changes: 0 additions & 23 deletions src/types/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ where
}
}

#[cfg(feature = "const-generics")]
impl<T, const N: usize> IntoPy<PyObject> for [T; N]
where
T: ToPyObject,
Expand All @@ -188,28 +187,6 @@ where
}
}

#[cfg(not(feature = "const-generics"))]
macro_rules! array_impls {
($($N:expr),+) => {
$(
impl<T> IntoPy<PyObject> for [T; $N]
where
T: ToPyObject
{
fn into_py(self, py: Python) -> PyObject {
self.as_ref().to_object(py)
}
}
)+
}
}

#[cfg(not(feature = "const-generics"))]
array_impls!(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32
);

impl<T> ToPyObject for Vec<T>
where
T: ToPyObject,
Expand Down
3 changes: 0 additions & 3 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,11 @@ mod string;
mod tuple;
mod typeobject;

#[cfg(feature = "const-generics")]
struct ArrayGuard<T, const N: usize> {
dst: *mut T,
initialized: usize,
}

#[cfg(feature = "const-generics")]
impl<T, const N: usize> Drop for ArrayGuard<T, N> {
fn drop(&mut self) {
debug_assert!(self.initialized <= N);
Expand All @@ -253,7 +251,6 @@ impl<T, const N: usize> Drop for ArrayGuard<T, N> {
}
}

#[cfg(feature = "const-generics")]
fn try_create_array<E, F, T, const N: usize>(mut cb: F) -> Result<[T; N], E>
where
F: FnMut(usize) -> Result<T, E>,
Expand Down
73 changes: 0 additions & 73 deletions src/types/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ impl PySequence {
}
}

#[cfg(feature = "const-generics")]
impl<'a, T, const N: usize> FromPyObject<'a> for [T; N]
where
T: FromPyObject<'a>,
Expand All @@ -273,7 +272,6 @@ where
}
}

#[cfg(all(feature = "const-generics", feature = "nightly"))]
impl<'source, T, const N: usize> FromPyObject<'source> for [T; N]
where
for<'a> T: FromPyObject<'a> + crate::buffer::Element,
Expand All @@ -291,59 +289,6 @@ where
}
}

#[cfg(not(feature = "const-generics"))]
macro_rules! array_impls {
($($N:expr),+) => {
$(
impl<'a, T> FromPyObject<'a> for [T; $N]
where
T: Copy + Default + FromPyObject<'a>,
{
#[cfg(not(feature = "nightly"))]
fn extract(obj: &'a PyAny) -> PyResult<Self> {
let mut array = [T::default(); $N];
extract_sequence_into_slice(obj, &mut array)?;
Ok(array)
}

#[cfg(feature = "nightly")]
default fn extract(obj: &'a PyAny) -> PyResult<Self> {
let mut array = [T::default(); $N];
extract_sequence_into_slice(obj, &mut array)?;
Ok(array)
}
}

#[cfg(feature = "nightly")]
impl<'source, T> FromPyObject<'source> for [T; $N]
where
for<'a> T: Default + FromPyObject<'a> + crate::buffer::Element,
{
fn extract(obj: &'source PyAny) -> PyResult<Self> {
let mut array = [T::default(); $N];
// first try buffer protocol
if let Ok(buf) = crate::buffer::PyBuffer::get(obj) {
if buf.dimensions() == 1 && buf.copy_to_slice(obj.py(), &mut array).is_ok() {
buf.release(obj.py());
return Ok(array);
}
buf.release(obj.py());
}
// fall back to sequence protocol
extract_sequence_into_slice(obj, &mut array)?;
Ok(array)
}
}
)+
}
}

#[cfg(not(feature = "const-generics"))]
array_impls!(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32
);

impl<'a, T> FromPyObject<'a> for Vec<T>
where
T: FromPyObject<'a>,
Expand Down Expand Up @@ -379,7 +324,6 @@ where
}
}

#[cfg(feature = "const-generics")]
fn create_array_from_obj<'s, T, const N: usize>(obj: &'s PyAny) -> PyResult<[T; N]>
where
T: FromPyObject<'s>,
Expand All @@ -406,23 +350,6 @@ where
Ok(v)
}

#[cfg(not(feature = "const-generics"))]
fn extract_sequence_into_slice<'s, T>(obj: &'s PyAny, slice: &mut [T]) -> PyResult<()>
where
T: FromPyObject<'s>,
{
let seq = <PySequence as PyTryFrom>::try_from(obj)?;
if seq.len()? as usize != slice.len() {
return Err(exceptions::PyBufferError::py_err(
"Slice length does not match buffer length.",
));
}
for (value, item) in slice.iter_mut().zip(seq.iter()?) {
*value = item?.extract::<T>()?;
}
Ok(())
}

impl<'v> PyTryFrom<'v> for PySequence {
fn try_from<V: Into<&'v PyAny>>(value: V) -> Result<&'v PySequence, PyDowncastError<'v>> {
let value = value.into();
Expand Down

0 comments on commit 5a8ef29

Please sign in to comment.