Skip to content

Commit a40307b

Browse files
committed
Adds formatting for ArrayRef
1 parent 2b34bf8 commit a40307b

File tree

1 file changed

+79
-4
lines changed

1 file changed

+79
-4
lines changed

src/arrayformat.rs

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88
use super::{ArrayBase, ArrayView, Axis, Data, Dimension, NdProducer};
9-
use crate::aliases::{Ix1, IxDyn};
9+
use crate::{
10+
aliases::{Ix1, IxDyn},
11+
ArrayRef,
12+
};
1013
use alloc::format;
1114
use std::fmt;
1215

@@ -112,13 +115,12 @@ fn format_with_overflow(
112115
Ok(())
113116
}
114117

115-
fn format_array<A, S, D, F>(
116-
array: &ArrayBase<S, D>, f: &mut fmt::Formatter<'_>, format: F, fmt_opt: &FormatOptions,
118+
fn format_array<A, D, F>(
119+
array: &ArrayRef<A, D>, f: &mut fmt::Formatter<'_>, format: F, fmt_opt: &FormatOptions,
117120
) -> fmt::Result
118121
where
119122
F: FnMut(&A, &mut fmt::Formatter<'_>) -> fmt::Result + Clone,
120123
D: Dimension,
121-
S: Data<Elem = A>,
122124
{
123125
// Cast into a dynamically dimensioned view
124126
// This is required to be able to use `index_axis` for the recursive case
@@ -174,6 +176,18 @@ where
174176
/// The array is shown in multiline style.
175177
impl<A: fmt::Display, S, D: Dimension> fmt::Display for ArrayBase<S, D>
176178
where S: Data<Elem = A>
179+
{
180+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
181+
{
182+
(**self).fmt(f)
183+
}
184+
}
185+
186+
/// Format the array reference using `Display` and apply the formatting parameters
187+
/// used to each element.
188+
///
189+
/// The array is shown in multiline style.
190+
impl<A: fmt::Display, D: Dimension> fmt::Display for ArrayRef<A, D>
177191
{
178192
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
179193
{
@@ -188,6 +202,18 @@ where S: Data<Elem = A>
188202
/// The array is shown in multiline style.
189203
impl<A: fmt::Debug, S, D: Dimension> fmt::Debug for ArrayBase<S, D>
190204
where S: Data<Elem = A>
205+
{
206+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
207+
{
208+
(**self).fmt(f)
209+
}
210+
}
211+
212+
/// Format the array reference using `Debug` and apply the formatting parameters used
213+
/// to each element.
214+
///
215+
/// The array is shown in multiline style.
216+
impl<A: fmt::Debug, D: Dimension> fmt::Debug for ArrayRef<A, D>
191217
{
192218
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
193219
{
@@ -216,6 +242,18 @@ where S: Data<Elem = A>
216242
/// The array is shown in multiline style.
217243
impl<A: fmt::LowerExp, S, D: Dimension> fmt::LowerExp for ArrayBase<S, D>
218244
where S: Data<Elem = A>
245+
{
246+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
247+
{
248+
(**self).fmt(f)
249+
}
250+
}
251+
252+
/// Format the array reference using `LowerExp` and apply the formatting parameters used
253+
/// to each element.
254+
///
255+
/// The array is shown in multiline style.
256+
impl<A: fmt::LowerExp, D: Dimension> fmt::LowerExp for ArrayRef<A, D>
219257
{
220258
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
221259
{
@@ -230,19 +268,44 @@ where S: Data<Elem = A>
230268
/// The array is shown in multiline style.
231269
impl<A: fmt::UpperExp, S, D: Dimension> fmt::UpperExp for ArrayBase<S, D>
232270
where S: Data<Elem = A>
271+
{
272+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
273+
{
274+
(**self).fmt(f)
275+
}
276+
}
277+
278+
/// Format the array using `UpperExp` and apply the formatting parameters used
279+
/// to each element.
280+
///
281+
/// The array is shown in multiline style.
282+
impl<A: fmt::UpperExp, D: Dimension> fmt::UpperExp for ArrayRef<A, D>
233283
{
234284
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
235285
{
236286
let fmt_opt = FormatOptions::default_for_array(self.len(), f.alternate());
237287
format_array(self, f, <_>::fmt, &fmt_opt)
238288
}
239289
}
290+
240291
/// Format the array using `LowerHex` and apply the formatting parameters used
241292
/// to each element.
242293
///
243294
/// The array is shown in multiline style.
244295
impl<A: fmt::LowerHex, S, D: Dimension> fmt::LowerHex for ArrayBase<S, D>
245296
where S: Data<Elem = A>
297+
{
298+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
299+
{
300+
(**self).fmt(f)
301+
}
302+
}
303+
304+
/// Format the array using `LowerHex` and apply the formatting parameters used
305+
/// to each element.
306+
///
307+
/// The array is shown in multiline style.
308+
impl<A: fmt::LowerHex, D: Dimension> fmt::LowerHex for ArrayRef<A, D>
246309
{
247310
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
248311
{
@@ -257,6 +320,18 @@ where S: Data<Elem = A>
257320
/// The array is shown in multiline style.
258321
impl<A: fmt::Binary, S, D: Dimension> fmt::Binary for ArrayBase<S, D>
259322
where S: Data<Elem = A>
323+
{
324+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
325+
{
326+
(**self).fmt(f)
327+
}
328+
}
329+
330+
/// Format the array using `Binary` and apply the formatting parameters used
331+
/// to each element.
332+
///
333+
/// The array is shown in multiline style.
334+
impl<A: fmt::Binary, D: Dimension> fmt::Binary for ArrayRef<A, D>
260335
{
261336
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
262337
{

0 commit comments

Comments
 (0)