pub struct ArrayFormatter<'a> { /* private fields */ }
Expand description
A string formatter for an Array
This can be used with std::write
to write type-erased dyn Array
struct MyContainer {
values: ArrayRef,
}
impl Display for MyContainer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let options = FormatOptions::default();
let formatter = ArrayFormatter::try_new(self.values.as_ref(), &options)
.map_err(|_| std::fmt::Error)?;
let mut iter = 0..self.values.len();
if let Some(idx) = iter.next() {
write!(f, "{}", formatter.value(idx))?;
}
for idx in iter {
write!(f, ", {}", formatter.value(idx))?;
}
Ok(())
}
}
ValueFormatter::write
can also be used to get a semantic error, instead of the
opaque std::fmt::Error
fn format_array(
f: &mut dyn Write,
array: &dyn Array,
options: &FormatOptions,
) -> Result<(), ArrowError> {
let formatter = ArrayFormatter::try_new(array, options)?;
for i in 0..array.len() {
formatter.value(i).write(f)?
}
Ok(())
}
Implementations§
Source§impl<'a> ArrayFormatter<'a>
impl<'a> ArrayFormatter<'a>
Sourcepub fn try_new(
array: &'a dyn Array,
options: &FormatOptions<'a>,
) -> Result<Self, ArrowError>
pub fn try_new( array: &'a dyn Array, options: &FormatOptions<'a>, ) -> Result<Self, ArrowError>
Returns an ArrayFormatter
that can be used to format array
This returns an error if an array of the given data type cannot be formatted
Sourcepub fn value(&self, idx: usize) -> ValueFormatter<'_>
pub fn value(&self, idx: usize) -> ValueFormatter<'_>
Returns a ValueFormatter
that implements Display
for
the value of the array at idx
Auto Trait Implementations§
impl<'a> Freeze for ArrayFormatter<'a>
impl<'a> !RefUnwindSafe for ArrayFormatter<'a>
impl<'a> !Send for ArrayFormatter<'a>
impl<'a> !Sync for ArrayFormatter<'a>
impl<'a> Unpin for ArrayFormatter<'a>
impl<'a> !UnwindSafe for ArrayFormatter<'a>
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