Skip to main content

AsdfBuilder

Struct AsdfBuilder 

Source
pub struct AsdfBuilder { /* private fields */ }
Expand description

Builds an ASDF file.

Implementations§

Source§

impl AsdfBuilder

Source

pub fn new() -> Self

A builder for a new, empty file.

Source

pub fn with_compression(self, compression: Compression) -> Self

Compress every array written from here on.

Blocks already in the builder – those an AsdfFile::edit brought over – keep the compression they had. Use AsdfBuilder::recompress to change those too.

Source

pub fn recompress(self, compression: Compression) -> Self

Compress every block, including those already here.

This is how a whole file’s compression is changed: open it, edit it, recompress, write it back. Each block’s data is already decompressed in the builder, so this only decides how it goes out.

Source

pub fn document_mut(&mut self) -> &mut Document

The tree being built, for direct manipulation.

Source

pub fn set_str(&mut self, path: &str, value: &str) -> Result<()>

Set a string. It is quoted where needed so it reads back as a string.

Source

pub fn set_i64(&mut self, path: &str, value: i64) -> Result<()>

Set a signed integer.

Source

pub fn set_u64(&mut self, path: &str, value: u64) -> Result<()>

Set an unsigned integer.

Source

pub fn set_f64(&mut self, path: &str, value: f64) -> Result<()>

Set a float.

Source

pub fn set_bool(&mut self, path: &str, value: bool) -> Result<()>

Set a boolean.

Source

pub fn set_null(&mut self, path: &str) -> Result<()>

Set a null.

Source

pub fn set_array<T: ArrayElement>( &mut self, path: &str, values: &[T], ) -> Result<()>

Write a one-dimensional array of any scalar type.

let mut builder = asdf::AsdfBuilder::new();
builder.set_array("counts", &[1u16, 2, 3])?;
builder.set_array("ratios", &[0.5f32, 1.5])?;
Source

pub fn set_array_shaped<T: ArrayElement>( &mut self, path: &str, values: &[T], shape: &[u64], ) -> Result<()>

Write a multi-dimensional array of any scalar type.

The data is taken in C order, and its length must match the shape.

Source

pub fn set_array_u64(&mut self, path: &str, values: &[u64]) -> Result<()>

Write a one-dimensional u64 array. See AsdfBuilder::set_array.

Source

pub fn set_array_i64(&mut self, path: &str, values: &[i64]) -> Result<()>

Write a one-dimensional i64 array. See AsdfBuilder::set_array.

Source

pub fn set_array_f64(&mut self, path: &str, values: &[f64]) -> Result<()>

Write a one-dimensional f64 array. See AsdfBuilder::set_array.

Source

pub fn set_array_f64_shaped( &mut self, path: &str, values: &[f64], shape: &[u64], ) -> Result<()>

Write a multi-dimensional f64 array.

See AsdfBuilder::set_array_shaped.

Source

pub fn add_block(&mut self, data: Vec<u8>) -> usize

Add a raw binary block, returning its index.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

Assemble the file in memory.

Source

pub fn write_to_path(&self, path: impl AsRef<Path>) -> Result<()>

Write the file to a path.

Source

pub fn write_to(&self, sink: &mut impl Write) -> Result<()>

Write the file to a stream.

Trait Implementations§

Source§

impl Debug for AsdfBuilder

Source§

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

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

impl Default for AsdfBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.