Struct datafusion_python::datafusion_common::arrow::util::display::ArrayFormatter
source · 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<ArrayFormatter<'a>, ArrowError>
pub fn try_new( array: &'a dyn Array, options: &FormatOptions<'a>, ) -> Result<ArrayFormatter<'a>, 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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more