Skip to main content

Builder

Struct Builder 

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

Builds a TFS image.

Implementations§

Source§

impl Builder

Source

pub fn new(total_blocks: usize) -> Builder

A freshly formatted image of total_blocks blocks.

The layout is derived rather than fixed: the allocation map is sized to cover the image at one tryte per block, and the inode table is sized to one inode per four blocks, which is generous for a small disk and costs little.

Source

pub fn finish(self) -> Vec<u8> ⓘ

The finished image.

Source

pub fn from_image(bytes: Vec<u8>) -> Builder

Reopens an existing image, reading its layout from the superblock.

For a host inspecting what a guest wrote. The layout fields are read back rather than recomputed, so an image built by something else is still readable as long as its superblock is honest.

Source

pub fn dir_len(&self, inode: i64) -> i64

How many entries a directory holds.

Source

pub fn inode_direct(&self, inode: i64, index: usize) -> i64

A direct block pointer of an inode, for a host checking allocation.

Source

pub fn inode_kind(&self, inode: i64) -> i64

The kind of an inode, for a host checking what a guest created.

Source

pub fn read_file(&self, inode: i64) -> Vec<u8> ⓘ

The contents of a file inode.

Source

pub fn bytes(&self) -> &[u8] ⓘ

The bytes so far, for inspection without consuming the builder.

Source

pub fn data_start(&self) -> usize

First block available for data.

Source

pub fn is_block_used(&self, block: usize) -> bool

True if the allocation map marks block as in use.

Source

pub fn lookup(&self, dir: i64, name: &str) -> Option<i64>

Finds name in directory dir.

Source

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

Creates a directory at path, which must not already exist.

Parent directories must exist. path is absolute with or without a leading slash.

Source

pub fn write_file(&mut self, path: &str, data: &[u8]) -> Result<i64, BuildError>

Creates a file at path holding data, one byte per tryte.

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> 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.