ndarray/layout/layoutfmt.rs
1// Copyright 2017 bluss and ndarray developers.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use super::Layout;
10
11const LAYOUT_NAMES: &[&str] = &["C", "F", "c", "f"];
12
13use std::fmt;
14
15impl fmt::Debug for Layout {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 if self.0 == 0 {
18 write!(f, "Custom")?
19 } else {
20 (0..32).filter(|&i| self.is(1 << i)).try_fold((), |_, i| {
21 if let Some(name) = LAYOUT_NAMES.get(i) {
22 write!(f, "{}", name)
23 } else {
24 write!(f, "{:#x}", i)
25 }
26 })?;
27 };
28 write!(f, " ({:#x})", self.0)
29 }
30}