#[repr(transparent)]pub struct PyFixedUnicode<const N: usize>(pub [Py_UCS4; N]);Expand description
A newtype wrapper around [PyUCS4; N] to handle str_ scalars while satisfying coherence.
Note that when creating arrays of Unicode strings without an explicit dtype,
NumPy will automatically determine the smallest possible array length at runtime.
For example,
numpy.array(["foo๐", "bar๐ฆ", "foobar"])yields U6 for array.dtype.
On the Rust side however, the length N of PyFixedUnicode<N> must always be given
explicitly and as a compile-time constant. For this work reliably, the Python code
should set the dtype explicitly, e.g.
numpy.array(["foo๐", "bar๐ฆ", "foobar"], dtype='U12')always matching PyArray1<PyFixedUnicode<12>>.
ยงExample
use numpy::{PyArray1, PyUntypedArrayMethods, PyFixedUnicode};
let array = PyArray1::<PyFixedUnicode<3>>::from_vec(py, vec![[b'b' as _, b'a' as _, b'r' as _].into()]);
assert!(array.dtype().to_string().contains("U3"));Tuple Fieldsยง
ยง0: [Py_UCS4; N]Trait Implementationsยง
Sourceยงimpl<const N: usize> Clone for PyFixedUnicode<N>
impl<const N: usize> Clone for PyFixedUnicode<N>
Sourceยงfn clone(&self) -> PyFixedUnicode<N>
fn clone(&self) -> PyFixedUnicode<N>
Returns a duplicate of the value. Read more
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSourceยงimpl<const N: usize> Debug for PyFixedUnicode<N>
impl<const N: usize> Debug for PyFixedUnicode<N>
Sourceยงimpl<const N: usize> Display for PyFixedUnicode<N>
impl<const N: usize> Display for PyFixedUnicode<N>
Sourceยงimpl<const N: usize> Element for PyFixedUnicode<N>
impl<const N: usize> Element for PyFixedUnicode<N>
Sourceยงconst IS_COPY: bool = true
const IS_COPY: bool = true
Flag that indicates whether this type is trivially copyable. Read more
Sourceยงfn get_dtype(py: Python<'_>) -> Bound<'_, PyArrayDescr>
fn get_dtype(py: Python<'_>) -> Bound<'_, PyArrayDescr>
Returns the associated type descriptor (โdtypeโ) for the given element type.
Sourceยงfn clone_ref(&self, _py: Python<'_>) -> Self
fn clone_ref(&self, _py: Python<'_>) -> Self
Create a clone of the value while the GIL is guaranteed to be held.
Sourceยงimpl<const N: usize> Hash for PyFixedUnicode<N>
impl<const N: usize> Hash for PyFixedUnicode<N>
Sourceยงimpl<const N: usize> Ord for PyFixedUnicode<N>
impl<const N: usize> Ord for PyFixedUnicode<N>
Sourceยงfn cmp(&self, other: &PyFixedUnicode<N>) -> Ordering
fn cmp(&self, other: &PyFixedUnicode<N>) -> Ordering
1.21.0 ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Sourceยงimpl<const N: usize> PartialEq for PyFixedUnicode<N>
impl<const N: usize> PartialEq for PyFixedUnicode<N>
Sourceยงimpl<const N: usize> PartialOrd for PyFixedUnicode<N>
impl<const N: usize> PartialOrd for PyFixedUnicode<N>
impl<const N: usize> Copy for PyFixedUnicode<N>
impl<const N: usize> Eq for PyFixedUnicode<N>
impl<const N: usize> StructuralPartialEq for PyFixedUnicode<N>
Auto Trait Implementationsยง
impl<const N: usize> Freeze for PyFixedUnicode<N>
impl<const N: usize> RefUnwindSafe for PyFixedUnicode<N>
impl<const N: usize> Send for PyFixedUnicode<N>
impl<const N: usize> Sync for PyFixedUnicode<N>
impl<const N: usize> Unpin for PyFixedUnicode<N>
impl<const N: usize> UnwindSafe for PyFixedUnicode<N>
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงimpl<T> Pointable for T
impl<T> Pointable for T
Sourceยงimpl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Sourceยงfn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSourceยงfn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Sourceยงfn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Sourceยงfn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.