Enum RegionRef

Source
pub enum RegionRef<'a> {
    Borrowed(&'a Region),
    Owned(Box<Region>),
}
Expand description

A wrapper around Region that allows either a reference to be used or a Box over return types.

Deref is implemented for this enum, so in theory, there should never be a need to match on this.

This is primarily used in the RegionParser trait, so that the implementers can return either a reference to or a box of a Region.

Variants§

§

Borrowed(&'a Region)

Borrowed Region (via reference)

§

Owned(Box<Region>)

Owned Region (via box)

Methods from Deref<Target = Region>§

Source

pub fn validate(&self) -> Result<()>

Validate that this Region contains all valid chunks by trying to parse every chunk.

§Important Note
  • This method is obviously slow and uses a decent amount of memory. It is recommended to assume the data is correct and validate it as you use the Region::get_chunk and Chunk::parse methods.
  • This method should only be used when you absolutely need to validate the data is correct and can’t use the Region::get_chunk and Chunk::parse methods
Source

pub fn get_timestamp(&self, x: u32, z: u32) -> u32

Get a timestamp for a chunk in this Region

§Panics
  • If x and z are not within 0..=31
Source

pub fn has_chunk(&self, x: u32, z: u32) -> bool

Check if the chunk at x and z have been generated

§Panics
  • If x and z are not within 0..=31
Source

pub fn get_chunk(&self, chunk_x: u32, chunk_z: u32) -> Result<Option<&Chunk>>

Get a chunk from this Region using relative coordinates within the region

§Return Values
  • Err if data is invalid
  • Ok(None) if the data is valid, but there is no chunk generated
  • Ok(Some(&Chunk)) if the data is valid and the chunk exists

This will return a &Chunk which references this Region, if you want an owned version, call Chunk::boxed on the returned chunk.

§Panics
  • If x and z are not within 0..=31
Source

pub fn get_chunk_from_block( &self, block_x: u32, block_z: u32, ) -> Result<Option<&Chunk>>

Get a chunk from this Region using relative block coordinates within the region

§Return Values
  • Err if data is invalid
  • Ok(None) if the data is valid, but there is no chunk generated
  • Ok(Some(&Chunk)) if the data is valid and the chunk exists

This will return a &Chunk which references this Region, if you want an owned version, call Chunk::boxed on the returned chunk.

§Panics
  • If x and z are not within 0..=511

Trait Implementations§

Source§

impl<'a> Debug for RegionRef<'a>

Source§

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

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

impl Deref for RegionRef<'_>

Source§

type Target = Region

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> From<&'a Region> for RegionRef<'a>

Source§

fn from(value: &'a Region) -> Self

Converts to this type from the input type.
Source§

impl From<Box<Region>> for RegionRef<'_>

Source§

fn from(value: Box<Region>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for RegionRef<'a>

§

impl<'a> RefUnwindSafe for RegionRef<'a>

§

impl<'a> Send for RegionRef<'a>

§

impl<'a> Sync for RegionRef<'a>

§

impl<'a> Unpin for RegionRef<'a>

§

impl<'a> UnwindSafe for RegionRef<'a>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.