Struct fastanvil::Region

source ·
pub struct Region<S> { /* private fields */ }
Expand description

A Minecraft Region, allowing reading and writing of chunk data to a stream (eg a File). This does not concern itself with manipulating chunk data, users are expected to use fastnbt or other deserialization method to manipulate the chunk data itself.

Implementations§

source§

impl<S> Region<S>where S: Read + Seek,

source

pub fn from_stream(stream: S) -> Result<Self>

Load a region from an existing stream. Will assume a seek of zero is the start of the region. This does not load all region data into memory. Chunks are read from the underlying stream when needed.

source

pub fn read_chunk(&mut self, x: usize, z: usize) -> Result<Option<Vec<u8>>>

Read the chunk located at the chunk coordindates x, z. The chunk data returned is uncompressed NBT. Ok(None) means that the chunk does not exist, which will be the case if that chunk has not generated. If x or z are outside 0..32, Error::InvalidOffset is returned.

source

pub fn into_inner(self) -> Result<S>

Return the inner buffer used. The buffer is rewound to the beginning.

source

pub fn iter(&mut self) -> RegionIter<'_, S>

source§

impl<S> Region<S>where S: Read + Write + Seek,

source

pub fn new(stream: S) -> Result<Self>

Create an new empty region. The provided stream will be overwritten, and will assume a seek to 0 is the start of the region. The stream needs read, write, and seek like a file provides.

source

pub fn write_chunk( &mut self, x: usize, z: usize, uncompressed_chunk: &[u8] ) -> Result<()>

Write the given uncompressed NBT chunk data to the chunk coordinates x, z. The chunk data will be compressed with zlib by default. You can use write_compressed_chunk if you want more control. If x or z are outside 0..32, Error::InvalidOffset is returned.

source

pub fn write_compressed_chunk( &mut self, x: usize, z: usize, scheme: CompressionScheme, compressed_chunk: &[u8] ) -> Result<()>

Low level method. Write the given compressed chunk data to the stream. It is the callers responsibility to make sure the compression scheme matches the compression used. If x or z are outside 0..32, Error::InvalidOffset is returned.

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for Region<S>where S: RefUnwindSafe,

§

impl<S> Send for Region<S>where S: Send,

§

impl<S> Sync for Region<S>where S: Sync,

§

impl<S> Unpin for Region<S>where S: Unpin,

§

impl<S> UnwindSafe for Region<S>where S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.