Skip to main content

ArrayMetadata

Enum ArrayMetadata 

Source
pub enum ArrayMetadata {
    V3(ArrayMetadataV3),
    V2(ArrayMetadataV2),
}
Expand description

Zarr array metadata (V2 or V3).

Variants§

§

V3(ArrayMetadataV3)

Zarr Version 3.

§

V2(ArrayMetadataV2)

Zarr Version 2.

Implementations§

Source§

impl ArrayMetadata

Source

pub fn to_string_pretty(&self) -> String

Serialize the metadata as a pretty-printed String of JSON.

Examples found in repository?
examples/custom_data_type_variable_size.rs (line 181)
157fn main() {
158    let store = std::sync::Arc::new(MemoryStore::default());
159    let array_path = "/array";
160    let array = ArrayBuilder::new(
161        vec![4, 1], // array shape
162        vec![3, 1], // regular chunk shape
163        Arc::new(CustomDataTypeVariableSize),
164        [],
165    )
166    .array_to_array_codecs(vec![
167        #[cfg(feature = "transpose")]
168        Arc::new(zarrs::array::codec::TransposeCodec::new(
169            zarrs::array::codec::array_to_array::transpose::TransposeOrder::new(&[1, 0]).unwrap(),
170        )),
171    ])
172    .bytes_to_bytes_codecs(vec![
173        #[cfg(feature = "gzip")]
174        Arc::new(zarrs::array::codec::GzipCodec::new(5).unwrap()),
175        #[cfg(feature = "crc32c")]
176        Arc::new(zarrs::array::codec::Crc32cCodec::new()),
177    ])
178    // .storage_transformers(vec![].into())
179    .build(store, array_path)
180    .unwrap();
181    println!("{}", array.metadata().to_string_pretty());
182
183    let data = [
184        CustomDataTypeVariableSizeElement::from(Some(1.0)),
185        CustomDataTypeVariableSizeElement::from(None),
186        CustomDataTypeVariableSizeElement::from(Some(3.0)),
187    ];
188    array.store_chunk(&[0, 0], &data).unwrap();
189
190    let data: Vec<CustomDataTypeVariableSizeElement> =
191        array.retrieve_array_subset(&array.subset_all()).unwrap();
192
193    assert_eq!(data[0], CustomDataTypeVariableSizeElement::from(Some(1.0)));
194    assert_eq!(data[1], CustomDataTypeVariableSizeElement::from(None));
195    assert_eq!(data[2], CustomDataTypeVariableSizeElement::from(Some(3.0)));
196    assert_eq!(data[3], CustomDataTypeVariableSizeElement::from(None));
197
198    println!("{data:#?}");
199}
More examples
Hide additional examples
examples/custom_data_type_fixed_size.rs (line 305)
280fn main() {
281    let store = std::sync::Arc::new(MemoryStore::default());
282    let array_path = "/array";
283    let fill_value = CustomDataTypeFixedSizeElement { x: 1, y: 2.3 };
284    let array = ArrayBuilder::new(
285        vec![4, 1], // array shape
286        vec![2, 1], // regular chunk shape
287        Arc::new(CustomDataTypeFixedSize),
288        FillValue::new(fill_value.to_ne_bytes().to_vec()),
289    )
290    .array_to_array_codecs(vec![
291        #[cfg(feature = "transpose")]
292        Arc::new(zarrs::array::codec::TransposeCodec::new(
293            zarrs::array::codec::array_to_array::transpose::TransposeOrder::new(&[1, 0]).unwrap(),
294        )),
295    ])
296    .bytes_to_bytes_codecs(vec![
297        #[cfg(feature = "gzip")]
298        Arc::new(zarrs::array::codec::GzipCodec::new(5).unwrap()),
299        #[cfg(feature = "crc32c")]
300        Arc::new(zarrs::array::codec::Crc32cCodec::new()),
301    ])
302    // .storage_transformers(vec![].into())
303    .build(store, array_path)
304    .unwrap();
305    println!("{}", array.metadata().to_string_pretty());
306
307    let data = [
308        CustomDataTypeFixedSizeElement { x: 3, y: 4.5 },
309        CustomDataTypeFixedSizeElement { x: 6, y: 7.8 },
310    ];
311    array.store_chunk(&[0, 0], &data).unwrap();
312
313    let data: Vec<CustomDataTypeFixedSizeElement> =
314        array.retrieve_array_subset(&array.subset_all()).unwrap();
315
316    assert_eq!(data[0], CustomDataTypeFixedSizeElement { x: 3, y: 4.5 });
317    assert_eq!(data[1], CustomDataTypeFixedSizeElement { x: 6, y: 7.8 });
318    assert_eq!(data[2], CustomDataTypeFixedSizeElement { x: 1, y: 2.3 });
319    assert_eq!(data[3], CustomDataTypeFixedSizeElement { x: 1, y: 2.3 });
320
321    println!("{data:#?}");
322}
examples/custom_data_type_uint12.rs (line 218)
192fn main() {
193    let store = std::sync::Arc::new(MemoryStore::default());
194    let array_path = "/array";
195    let fill_value = CustomDataTypeUInt12Element::try_from(15).unwrap();
196    let array = ArrayBuilder::new(
197        vec![4096, 1], // array shape
198        vec![5, 1],    // regular chunk shape
199        Arc::new(CustomDataTypeUInt12),
200        FillValue::new(fill_value.into_le_bytes().to_vec()),
201    )
202    .array_to_array_codecs(vec![
203        #[cfg(feature = "transpose")]
204        Arc::new(zarrs::array::codec::TransposeCodec::new(
205            zarrs::array::codec::array_to_array::transpose::TransposeOrder::new(&[1, 0]).unwrap(),
206        )),
207    ])
208    .array_to_bytes_codec(Arc::new(zarrs::array::codec::PackBitsCodec::default()))
209    .bytes_to_bytes_codecs(vec![
210        #[cfg(feature = "gzip")]
211        Arc::new(zarrs::array::codec::GzipCodec::new(5).unwrap()),
212        #[cfg(feature = "crc32c")]
213        Arc::new(zarrs::array::codec::Crc32cCodec::new()),
214    ])
215    // .storage_transformers(vec![].into())
216    .build(store, array_path)
217    .unwrap();
218    println!("{}", array.metadata().to_string_pretty());
219
220    let data: Vec<CustomDataTypeUInt12Element> = (0..4096)
221        .map(|i| CustomDataTypeUInt12Element::try_from(i).unwrap())
222        .collect();
223
224    array
225        .store_array_subset(&array.subset_all(), &data)
226        .unwrap();
227
228    let mut data: Vec<CustomDataTypeUInt12Element> =
229        array.retrieve_array_subset(&array.subset_all()).unwrap();
230
231    for (i, d) in data.drain(0..4096).enumerate() {
232        let element = CustomDataTypeUInt12Element::try_from(i as u64).unwrap();
233        assert_eq!(d, element);
234        let element_pd: Vec<CustomDataTypeUInt12Element> = array
235            .retrieve_array_subset(&[(i as u64)..i as u64 + 1, 0..1])
236            .unwrap();
237        assert_eq!(element_pd[0], element);
238    }
239}
examples/custom_data_type_float8_e3m4.rs (line 228)
203fn main() {
204    let store = std::sync::Arc::new(MemoryStore::default());
205    let array_path = "/array";
206    let fill_value = CustomDataTypeFloat8e3m4Element::from(1.23);
207    let array = ArrayBuilder::new(
208        vec![6, 1], // array shape
209        vec![5, 1], // regular chunk shape
210        Arc::new(CustomDataTypeFloat8e3m4),
211        FillValue::new(fill_value.into_ne_bytes().to_vec()),
212    )
213    .array_to_array_codecs(vec![
214        #[cfg(feature = "transpose")]
215        Arc::new(zarrs::array::codec::TransposeCodec::new(
216            zarrs::array::codec::array_to_array::transpose::TransposeOrder::new(&[1, 0]).unwrap(),
217        )),
218    ])
219    .bytes_to_bytes_codecs(vec![
220        #[cfg(feature = "gzip")]
221        Arc::new(zarrs::array::codec::GzipCodec::new(5).unwrap()),
222        #[cfg(feature = "crc32c")]
223        Arc::new(zarrs::array::codec::Crc32cCodec::new()),
224    ])
225    // .storage_transformers(vec![].into())
226    .build(store, array_path)
227    .unwrap();
228    println!("{}", array.metadata().to_string_pretty());
229
230    let data = [
231        CustomDataTypeFloat8e3m4Element::from(2.34),
232        CustomDataTypeFloat8e3m4Element::from(3.45),
233        CustomDataTypeFloat8e3m4Element::from(f32::INFINITY),
234        CustomDataTypeFloat8e3m4Element::from(f32::NEG_INFINITY),
235        CustomDataTypeFloat8e3m4Element::from(f32::NAN),
236    ];
237    array.store_chunk(&[0, 0], &data).unwrap();
238
239    let data: Vec<CustomDataTypeFloat8e3m4Element> =
240        array.retrieve_array_subset(&array.subset_all()).unwrap();
241
242    for f in &data {
243        println!(
244            "float8_e3m4: {:08b} f32: {}",
245            f.into_ne_bytes()[0],
246            f.into_f32()
247        );
248    }
249
250    assert_eq!(data[0], CustomDataTypeFloat8e3m4Element::from(2.34));
251    assert_eq!(data[1], CustomDataTypeFloat8e3m4Element::from(3.45));
252    assert_eq!(
253        data[2],
254        CustomDataTypeFloat8e3m4Element::from(f32::INFINITY)
255    );
256    assert_eq!(
257        data[3],
258        CustomDataTypeFloat8e3m4Element::from(f32::NEG_INFINITY)
259    );
260    assert_eq!(data[4], CustomDataTypeFloat8e3m4Element::from(f32::NAN));
261    assert_eq!(data[5], CustomDataTypeFloat8e3m4Element::from(1.23));
262}
examples/async_http_array_read.rs (line 54)
15async fn http_array_read(backend: Backend) -> Result<(), Box<dyn std::error::Error>> {
16    const HTTP_URL: &str =
17        "https://raw.githubusercontent.com/zarrs/zarrs/main/zarrs/tests/data/array_write_read.zarr";
18    const ARRAY_PATH: &str = "/group/array";
19
20    // Create a HTTP store
21    let mut store: AsyncReadableStorage = match backend {
22        // Backend::OpenDAL => {
23        //     let builder = opendal::services::Http::default().endpoint(HTTP_URL);
24        //     let operator = opendal::Operator::new(builder)?.finish();
25        //     Arc::new(zarrs_opendal::AsyncOpendalStore::new(operator))
26        // }
27        Backend::ObjectStore => {
28            let options = object_store::ClientOptions::new().with_allow_http(true);
29            let store = object_store::http::HttpBuilder::new()
30                .with_url(HTTP_URL)
31                .with_client_options(options)
32                .build()?;
33            Arc::new(zarrs_object_store::AsyncObjectStore::new(store))
34        }
35    };
36    if let Some(arg1) = std::env::args().collect::<Vec<_>>().get(1)
37        && arg1 == "--usage-log"
38    {
39        let log_writer = Arc::new(std::sync::Mutex::new(
40            // std::io::BufWriter::new(
41            std::io::stdout(),
42            //    )
43        ));
44        store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || {
45            chrono::Utc::now().format("[%T%.3f] ").to_string()
46        }));
47    }
48
49    // Init the existing array, reading metadata
50    let array = Array::async_open(store, ARRAY_PATH).await?;
51
52    println!(
53        "The array metadata is:\n{}\n",
54        array.metadata().to_string_pretty()
55    );
56
57    // Read the whole array
58    let data_all: ArrayD<f32> = array
59        .async_retrieve_array_subset(&array.subset_all())
60        .await?;
61    println!("The whole array is:\n{data_all}\n");
62
63    // Read a chunk back from the store
64    let chunk_indices = vec![1, 0];
65    let data_chunk: ArrayD<f32> = array.async_retrieve_chunk(&chunk_indices).await?;
66    println!("Chunk [1,0] is:\n{data_chunk}\n");
67
68    // Read the central 4x2 subset of the array
69    let subset_4x2 = ArraySubset::new_with_ranges(&[2..6, 3..5]); // the center 4x2 region
70    let data_4x2: ArrayD<f32> = array.async_retrieve_array_subset(&subset_4x2).await?;
71    println!("The middle 4x2 subset is:\n{data_4x2}\n");
72
73    Ok(())
74}
examples/custom_data_type_uint4.rs (line 220)
194fn main() {
195    let store = std::sync::Arc::new(MemoryStore::default());
196    let array_path = "/array";
197    let fill_value = CustomDataTypeUInt4Element::try_from(15).unwrap();
198    let array = ArrayBuilder::new(
199        vec![6, 1], // array shape
200        vec![5, 1], // regular chunk shape
201        Arc::new(CustomDataTypeUInt4),
202        FillValue::new(fill_value.into_ne_bytes().to_vec()),
203    )
204    .array_to_array_codecs(vec![
205        #[cfg(feature = "transpose")]
206        Arc::new(zarrs::array::codec::TransposeCodec::new(
207            zarrs::array::codec::array_to_array::transpose::TransposeOrder::new(&[1, 0]).unwrap(),
208        )),
209    ])
210    .array_to_bytes_codec(Arc::new(zarrs::array::codec::PackBitsCodec::default()))
211    .bytes_to_bytes_codecs(vec![
212        #[cfg(feature = "gzip")]
213        Arc::new(zarrs::array::codec::GzipCodec::new(5).unwrap()),
214        #[cfg(feature = "crc32c")]
215        Arc::new(zarrs::array::codec::Crc32cCodec::new()),
216    ])
217    // .storage_transformers(vec![].into())
218    .build(store, array_path)
219    .unwrap();
220    println!("{}", array.metadata().to_string_pretty());
221
222    let data = [
223        CustomDataTypeUInt4Element::try_from(1).unwrap(),
224        CustomDataTypeUInt4Element::try_from(2).unwrap(),
225        CustomDataTypeUInt4Element::try_from(3).unwrap(),
226        CustomDataTypeUInt4Element::try_from(4).unwrap(),
227        CustomDataTypeUInt4Element::try_from(5).unwrap(),
228    ];
229    array.store_chunk(&[0, 0], &data).unwrap();
230
231    let data: Vec<CustomDataTypeUInt4Element> =
232        array.retrieve_array_subset(&array.subset_all()).unwrap();
233
234    for f in &data {
235        println!("uint4: {:08b} u8: {}", f.into_u8(), f.into_u8());
236    }
237
238    assert_eq!(data[0], CustomDataTypeUInt4Element::try_from(1).unwrap());
239    assert_eq!(data[1], CustomDataTypeUInt4Element::try_from(2).unwrap());
240    assert_eq!(data[2], CustomDataTypeUInt4Element::try_from(3).unwrap());
241    assert_eq!(data[3], CustomDataTypeUInt4Element::try_from(4).unwrap());
242    assert_eq!(data[4], CustomDataTypeUInt4Element::try_from(5).unwrap());
243    assert_eq!(data[5], CustomDataTypeUInt4Element::try_from(15).unwrap());
244
245    let data: Vec<CustomDataTypeUInt4Element> = array.retrieve_array_subset(&[1..3, 0..1]).unwrap();
246    assert_eq!(data[0], CustomDataTypeUInt4Element::try_from(2).unwrap());
247    assert_eq!(data[1], CustomDataTypeUInt4Element::try_from(3).unwrap());
248}

Trait Implementations§

Source§

impl Clone for ArrayMetadata

Source§

fn clone(&self) -> ArrayMetadata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ArrayMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ArrayMetadata

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ArrayMetadata, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ArrayMetadata

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<ArrayMetadataV2> for ArrayMetadata

Source§

fn from(value: ArrayMetadataV2) -> ArrayMetadata

Converts to this type from the input type.
Source§

impl From<ArrayMetadataV3> for ArrayMetadata

Source§

fn from(value: ArrayMetadataV3) -> ArrayMetadata

Converts to this type from the input type.
Source§

impl PartialEq for ArrayMetadata

Source§

fn eq(&self, other: &ArrayMetadata) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ArrayMetadata

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&str> for ArrayMetadata

Source§

type Error = Error

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

fn try_from( metadata_json: &str, ) -> Result<ArrayMetadata, <ArrayMetadata as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for ArrayMetadata

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,