#[repr(transparent)]pub struct PyFixedUnicode<const N: usize>(pub [Py_UCS4; N]);Expand description
A newtype wrapper around [[PyUCS4; N]][Py_UCS4] 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ยงfn vec_from_slice(_py: Python<'_>, slc: &[Self]) -> Vec<Self>
fn vec_from_slice(_py: Python<'_>, slc: &[Self]) -> Vec<Self>
Create an owned copy of the slice while the GIL is guaranteed to be held. Read more
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,
ยงimpl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
ยง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 moreยง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).ยง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.ยงfn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.