pub struct StringArray<D: Dimension> { /* private fields */ }Expand description
A specialized N-dimensional array of strings.
Unlike ferray_core::Array, this type does not require Element —
it stores Vec<String> directly with shape metadata for indexing.
The data is stored in row-major (C) order.
Implementations§
Source§impl<D: Dimension> StringArray<D>
impl<D: Dimension> StringArray<D>
Sourcepub fn from_vec(dim: D, data: Vec<String>) -> FerrayResult<Self>
pub fn from_vec(dim: D, data: Vec<String>) -> FerrayResult<Self>
Create a new StringArray from a flat vector of strings and a shape.
§Errors
Returns FerrayError::ShapeMismatch if data.len() does not equal
the product of the shape dimensions.
Sourcepub fn empty(dim: D) -> FerrayResult<Self>
pub fn empty(dim: D) -> FerrayResult<Self>
Create a StringArray filled with empty strings.
§Errors
This function is infallible for valid shapes but returns Result
for API consistency.
Sourcepub fn as_slice_mut(&mut self) -> &mut [String]
pub fn as_slice_mut(&mut self) -> &mut [String]
Return a mutable reference to the flat data.
Sourcepub fn map<F>(&self, f: F) -> FerrayResult<Self>
pub fn map<F>(&self, f: F) -> FerrayResult<Self>
Apply a function to each element, producing a new StringArray.
Sourcepub fn map_to_vec<T, F>(&self, f: F) -> Vec<T>
pub fn map_to_vec<T, F>(&self, f: F) -> Vec<T>
Apply a function to each element, producing a Vec<T>.
This is a lower-level helper used by search and boolean operations
that need to produce typed arrays (e.g., Array<bool, D>).
Sourcepub fn reshape<D2: Dimension>(
self,
new_dim: D2,
) -> FerrayResult<StringArray<D2>>
pub fn reshape<D2: Dimension>( self, new_dim: D2, ) -> FerrayResult<StringArray<D2>>
Reshape this array to a new dimension type / shape. The total element count must be unchanged.
Since strings are cheap to move (they’re owned), reshape just rebuilds the array around the existing buffer. No data copy.
§Errors
Returns FerrayError::ShapeMismatch if the new shape’s
element count does not match self.len().
Sourcepub fn flatten(self) -> StringArray1
pub fn flatten(self) -> StringArray1
Flatten to a 1-D StringArray1 of length self.len(). The
row-major traversal order is preserved.
This is the string analogue of ndarray::Array::flatten /
NumPy’s arr.flatten().
Sourcepub fn into_dyn(self) -> StringArray<IxDyn>
pub fn into_dyn(self) -> StringArray<IxDyn>
Convert to a dynamic-rank StringArray<IxDyn>. Useful when
the rank isn’t known until runtime, or when interoperating
with code that only accepts IxDyn.
Sourcepub fn get(&self, idx: &[usize]) -> Option<&String>
pub fn get(&self, idx: &[usize]) -> Option<&String>
Look up an element by multi-dimensional index. Returns None
if the index is out of bounds.
Indexing is row-major (C-order): for a (rows, cols) array,
index [r, c] maps to data[r * cols + c].
Sourcepub fn at(&self, idx: usize) -> Option<&String>
pub fn at(&self, idx: usize) -> Option<&String>
Index by flat (row-major) offset (#519).
Equivalent to arr.iter().nth(idx) but O(1) — returns None
when idx >= len(). Useful when the caller already has a
linearised position.
Sourcepub fn slice_axis(
&self,
axis: usize,
range: Range<usize>,
) -> FerrayResult<StringArray<IxDyn>>
pub fn slice_axis( &self, axis: usize, range: Range<usize>, ) -> FerrayResult<StringArray<IxDyn>>
Take a contiguous range along axis and return a new
StringArray<IxDyn> (#519).
axis must be a valid axis for this array; range is a
half-open [start, end) window into that axis. The other
axes are preserved at their full size.
§Errors
FerrayError::AxisOutOfBounds if axis >= ndim. FerrayError::InvalidValue
if range exceeds the axis length or is empty in a way that
produces a zero-sized non-existent shape.
Sourcepub fn get_row(&self, idx: usize) -> FerrayResult<StringArray1>
pub fn get_row(&self, idx: usize) -> FerrayResult<StringArray1>
Extract row idx from a 2-D StringArray as a 1-D
StringArray (#519).
§Errors
FerrayError::ShapeMismatch if self is not 2-D, or
FerrayError::IndexOutOfBounds if idx exceeds the row count.
Source§impl StringArray<Ix1>
impl StringArray<Ix1>
Sourcepub fn from_slice(items: &[&str]) -> FerrayResult<Self>
pub fn from_slice(items: &[&str]) -> FerrayResult<Self>
Source§impl StringArray<Ix2>
impl StringArray<Ix2>
Sourcepub fn transpose(&self) -> FerrayResult<Self>
pub fn transpose(&self) -> FerrayResult<Self>
Transpose a 2-D StringArray: swap rows and columns.
Walks the elements into a new buffer — a (r, c) cell of the
input becomes (c, r) of the output. Strings are cloned to
avoid disturbing the original array.
Sourcepub fn from_rows(rows: &[&[&str]]) -> FerrayResult<Self>
pub fn from_rows(rows: &[&[&str]]) -> FerrayResult<Self>
Create a 2-D StringArray from nested slices.
§Errors
Returns FerrayError::ShapeMismatch if inner slices have different lengths.
Source§impl StringArray<IxDyn>
impl StringArray<IxDyn>
Sourcepub fn from_vec_dyn(shape: &[usize], data: Vec<String>) -> FerrayResult<Self>
pub fn from_vec_dyn(shape: &[usize], data: Vec<String>) -> FerrayResult<Self>
Create a dynamic-rank StringArray from a flat vec and a dynamic shape.
Trait Implementations§
Source§impl<D: Clone + Dimension> Clone for StringArray<D>
impl<D: Clone + Dimension> Clone for StringArray<D>
Source§fn clone(&self) -> StringArray<D>
fn clone(&self) -> StringArray<D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more