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<StringArray<D>>
pub fn map<F>(&self, f: F) -> FerrayResult<StringArray<D>>
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.
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<StringArray<Ix2>>
pub fn transpose(&self) -> FerrayResult<StringArray<Ix2>>
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