Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

StructRegion

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

A Minecraft Region, allowing reading and writing of chunk data to a stream (eg aFile). This does not concern itself with manipulating chunk data, users areexpected to usefastnbt or other deserialization method to manipulate thechunk data itself.

If using a stream withRead andSeek you can only read chunk data. Ifyou want to be able to modify chunk data you also need a stream implementingWrite.File implements these, as doesCursor<Vec<u8>>.

Implementations§

Source§

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

Source

pub fnfrom_stream(stream: S) ->Result<Self>

Load a region from an existing stream, meaning something that implementsRead andSeek. This will assume a seek of zero is the start ofthe region. This does not load all region data into memory immediately.Chunks are read from the underlying stream when needed.

The most obvious ‘stream’ is a file:

letfile = File::open("foo.mca")?;letmutregion = Region::from_stream(file)?;// manipulate region

If you have raw data, this can also be used by wrapping it in aCursor:

letdata: Vec<u8> =todo!("get data");letdata = Cursor::new(data);letmutregion = Region::from_stream(data)?;// manipulate region
Source

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

Read the chunk located at the chunk coordindatesx,z. The chunkdata returned is uncompressed NBT.Ok(None) means that the chunk doesnot exist, which will be the case if that chunk has not generated. Ifx orz are outside0..32,Error::InvalidOffset is returned.

usefastanvil::CurrentJavaChunk;letfile = File::open("foo.mca")?;letmutregion = Region::from_stream(file)?;// Get a chunk. May error for IO reasons, and may not be present, hence Result<Option>.letchunk = region.read_chunk(1,2).unwrap().unwrap();// Parse chunk data into a CurrentJavaChunk.letchunk: CurrentJavaChunk = fastnbt::from_bytes(&chunk).unwrap();
Source

pub fninto_inner(self) ->Result<S>

Return the inner buffer used. The buffer is rewound to the logical endof the region data. If the region does not contain any chunk the position is atthe end of the header. If saving to disk you should truncate the file tothis position to ensure the file is saved with the correct padding bytes.

§Examples

This can be used to truncate a region file after manipulating it to savedisk space.

letfile = File::open("foo.mca")?;letmutregion = Region::from_stream(file)?;// manipulate region// recover the file object in order to make sure the file is the correct// size on disk. The seek head is left at the exact end of the region data,// including required padding.letmutfile = region.into_inner()?;letlen = file.stream_position()?;file.set_len(len)?;
Source

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

Create an iterator for the chunks of the region. Chunks not present inthe file are skipped.

Source§

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

Source

pub fnnew(stream: S) ->Result<Self>

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

Source

pub fnwrite_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 usewrite_compressed_chunk if you want more control. Ifx orz areoutside0..32,Error::InvalidOffset is returned.

Source

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

Low level method to write the given compressed chunk data to the stream.

It is the callers responsibility to make sure the compression schemematches the compression used. Ifx orz are outside0..32,Error::InvalidOffset is returned.

Source

pub fnremove_chunk(&mut self, x:usize, z:usize) ->Result<()>

Remove the chunk at the chunk location with the coordinates x and z.

If you are stripping chunks from regions to save disk space, you shouldinstead iterate through the chunks of the region, and write the desiredchunks to a new region, and write that to disk. This will ensure chunks arecompactly stored with no gaps.

Trait Implementations§

Source§

impl<S:Clone>Clone forRegion<S>

Source§

fnclone(&self) ->Region<S>

Returns a duplicate of the value.Read more
1.0.0 ·Source§

fnclone_from(&mut self, source: &Self)

Performs copy-assignment fromsource.Read more

Auto Trait Implementations§

§

impl<S>Freeze forRegion<S>
where S:Freeze,

§

impl<S>RefUnwindSafe forRegion<S>
where S:RefUnwindSafe,

§

impl<S>Send forRegion<S>
where S:Send,

§

impl<S>Sync forRegion<S>
where S:Sync,

§

impl<S>Unpin forRegion<S>
where S:Unpin,

§

impl<S>UnwindSafe forRegion<S>
where S:UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

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

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

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

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>CloneToUninit for T
where T:Clone,

Source§

unsafe fnclone_to_uninit(&self, dest:*mutu8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment fromself todest.Read more
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fninto(self) -> U

CallsU::from(self).

That is, this conversion is whatever the implementation ofFrom<T> for U chooses to do.

Source§

impl<T>ToOwned for T
where T:Clone,

Source§

typeOwned = T

The resulting type after obtaining ownership.
Source§

fnto_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning.Read more
Source§

fnclone_into(&self, target:&mut T)

Uses borrowed data to replace owned data, usually by cloning.Read more
Source§

impl<T, U>TryFrom<U> for T
where U:Into<T>,

Source§

typeError =Infallible

The type returned in the event of a conversion error.
Source§

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

typeError = <U asTryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.

[8]ページ先頭

©2009-2025 Movatter.jp