arrow::util::display

Struct ArrayFormatter

pub struct ArrayFormatter<'a> {
    format: Box<dyn DisplayIndex + 'a>,
    safe: bool,
}
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(())
}

Fields§

§format: Box<dyn DisplayIndex + 'a>§safe: bool

Implementations§

§

impl<'a> ArrayFormatter<'a>

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

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V