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>
impl<W: Write> FrozenMapBuilder<W>
Sourcepub fn new(wtr: W) -> Result<Self, BuildError>
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.
Sourcepub fn insert(&mut self, index: CellIndex, value: u64) -> Result<(), BuildError>
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.
Sourcepub fn extend_iter(
&mut self,
iter: impl IntoIterator<Item = (CellIndex, u64)>,
) -> Result<(), BuildError>
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.
Sourcepub fn finish(self) -> Result<(), BuildError>
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.
Sourcepub fn into_inner(self) -> Result<W, BuildError>
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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