Struct FrozenMapBuilder

Source
pub struct FrozenMapBuilder<W>(/* private fields */);
Expand description

A builder for creating a frozen map.

§Example: build in memory

use h3o::{CellIndex, Resolution};
use h3o_ice::FrozenMapBuilder;

let mut builder = FrozenMapBuilder::memory();
builder.insert(CellIndex::try_from(0x85283473fffffff)?, 42)?;

let index = CellIndex::try_from(0x8a1fb46622dffff)?;
builder.extend_iter(
    index
        .children(Resolution::Six)
        .enumerate()
        .map(|(idx, cell)| (cell, idx as u64)),
)?;

let map = builder.into_map();

§Example: stream to file

use h3o::{CellIndex, Resolution};
use h3o_ice::FrozenMapBuilder;
use std::{fs, io};

let mut wtr = io::BufWriter::new(fs::File::create(file_path)?);
let mut builder = FrozenMapBuilder::new(wtr)?;

let index = CellIndex::try_from(0x8a1fb46622dffff)?;
builder.extend_iter(
    index
        .children(Resolution::Six)
        .enumerate()
        .map(|(idx, cell)| (cell, idx as u64)),
)?;

builder.finish()?;

Implementations§

Source§

impl<W: Write> FrozenMapBuilder<W>

Source

pub fn new(wtr: W) -> Result<Self, BuildError>

Create a builder that builds a map by writing it to wtr in a streaming fashion.

§Errors

If there was a problem writing to the underlying writer, an error is returned.

Source

pub fn insert(&mut self, index: CellIndex, value: u64) -> Result<(), BuildError>

Insert a new key-value pair into the map.

§Errors

If a cell index is inserted that is less than any previous cell index added, then an error is returned. Similarly, if there was a problem writing to the underlying writer, an error is returned.

Source

pub fn extend_iter( &mut self, iter: impl IntoIterator<Item = (CellIndex, u64)>, ) -> Result<(), BuildError>

Calls insert on each cell index in the iterator.

If an error occurred while adding an element, processing is stopped and the error is returned.

§Errors

If an error occurred while adding an element, processing is stopped and the error is returned.

Source

pub fn finish(self) -> Result<(), BuildError>

Finishes the construction of the map and flushes the underlying writer. After completion, the data written to W may be read using one of FrozenMap’s constructor methods.

§Errors

Returns an error if there was a problem writing to the underlying writer.

Source

pub fn into_inner(self) -> Result<W, BuildError>

Just like finish, except it returns the underlying writer after flushing it.

§Errors

Returns an error if there was a problem writing to the underlying writer.

Source§

impl FrozenMapBuilder<Vec<u8>>

Source

pub fn memory() -> Self

Create a builder that builds a map in memory.

Source

pub fn into_map(self) -> FrozenMap<Vec<u8>>

Finishes the construction of the map and returns it.

Auto Trait Implementations§

§

impl<W> Freeze for FrozenMapBuilder<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for FrozenMapBuilder<W>
where W: RefUnwindSafe,

§

impl<W> Send for FrozenMapBuilder<W>
where W: Send,

§

impl<W> Sync for FrozenMapBuilder<W>
where W: Sync,

§

impl<W> Unpin for FrozenMapBuilder<W>
where W: Unpin,

§

impl<W> UnwindSafe for FrozenMapBuilder<W>
where W: UnwindSafe,

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