### Result::is_ok_and Method Source: https://docs.rs/fastanvil/0.32.0/fastanvil/type.Result.html Example of checking if a Result is Ok and matches a predicate. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Result::is_ok Method Source: https://docs.rs/fastanvil/0.32.0/fastanvil/type.Result.html Example of checking if a Result is Ok. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` -------------------------------- ### Safely get Ok value (nightly) Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Result.html The `into_ok()` method returns the contained `Ok` value and is guaranteed not to panic. This is a nightly-only experimental API. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` -------------------------------- ### Split Vec Example Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Demonstrates splitting a vector into two parts using `split_off`. The original vector retains elements up to the split point, and the new vector contains the remaining elements. ```rust let mut vec = vec!['a', 'b', 'c']; let vec2 = vec.split_off(1); assert_eq!(vec, ['a']); assert_eq!(vec2, ['b', 'c']); ``` -------------------------------- ### Result Methods Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Result.html Examples and descriptions of common methods available on the Result type. ```APIDOC ## `sq_then_to_string` Example ### Description Demonstrates chaining fallible operations using `and_then`. ### Code Example ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ``` ```APIDOC ## `or` Method ### Description Returns `res` if the result is `Err`, otherwise returns the `Ok` value of `self`. Arguments passed to `or` are eagerly evaluated. ### Method `pub fn or(self, res: Result) -> Result` ### Examples ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` ``` ```APIDOC ## `or_else` Method ### Description Calls `op` if the result is `Err`, otherwise returns the `Ok` value of `self`. This function can be used for control flow based on result values. ### Method `pub fn or_else(self, op: O) -> Result` where O: FnOnce(E) -> Result ### Examples ```rust fn sq(x: u32) -> Result { Ok(x * x) } fn err(x: u32) -> Result { Err(x) } assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9)); assert_eq!(Err(3).or_else(err).or_else(err), Err(3)); ``` ``` ```APIDOC ## `unwrap_or` Method ### Description Returns the contained `Ok` value or a provided default. Arguments passed to `unwrap_or` are eagerly evaluated. ### Method `pub fn unwrap_or(self, default: T) -> T` ### Examples ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` ``` ```APIDOC ## `unwrap_or_else` Method ### Description Returns the contained `Ok` value or computes it from a closure. ### Method `pub fn unwrap_or_else(self, op: F) -> T` where F: FnOnce(E) -> T ### Examples ```rust fn count(x: &str) -> usize { x.len() } assert_eq!(Ok(2).unwrap_or_else(count), 2); assert_eq!(Err("foo").unwrap_or_else(count), 3); ``` ``` ```APIDOC ## `unwrap_unchecked` Method ### Description Returns the contained `Ok` value, consuming the `self` value, without checking that the value is not an `Err`. ### Safety Calling this method on an `Err` is _undefined behavior_. ### Method `pub unsafe fn unwrap_unchecked(self) -> T` ### Examples ```rust let x: Result = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2); ``` ```rust let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` ``` ```APIDOC ## `unwrap_err_unchecked` Method ### Description Returns the contained `Err` value, consuming the `self` value, without checking that the value is not an `Ok`. ### Safety Calling this method on an `Ok` is _undefined behavior_. ### Method `pub unsafe fn unwrap_err_unchecked(self) -> E` ### Examples ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure"); ``` ``` -------------------------------- ### Iterate over block state indices Source: https://docs.rs/fastanvil/0.32.0/fastanvil/pre18/struct.Pre18Blockstates.html Example showing how to recover coordinates from the block state iterator. ```rust for (i, block_index) in states.iter_indices(10).enumerate() { let x = i & 0x000F; let y = (i & 0x0F00) >> 8; let z = (i & 0x00F0) >> 4; } ``` -------------------------------- ### Result::copied Method Source: https://docs.rs/fastanvil/0.32.0/fastanvil/type.Result.html Examples of using the copied method on Result<&T, E> and Result<&mut T, E>. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### Result::cloned Method Source: https://docs.rs/fastanvil/0.32.0/fastanvil/type.Result.html Examples of using the cloned method on Result<&T, E> and Result<&mut T, E>. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### Renderer Initialization Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/struct.Renderer.html Creates a new instance of the Renderer with provided blockstates, models, and textures. ```APIDOC ## pub fn new ### Description Initializes a new Renderer instance with the required mapping data. ### Parameters - **blockstates** (HashMap) - Required - Map of blockstate identifiers to their definitions. - **models** (HashMap) - Required - Map of model identifiers to their definitions. - **textures** (HashMap) - Required - Map of texture identifiers to their definitions. ``` -------------------------------- ### Result::is_err Method Source: https://docs.rs/fastanvil/0.32.0/fastanvil/type.Result.html Example of checking if a Result is Err. ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Vec with Capacity and System Allocator Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Demonstrates creating a Vec with a specific capacity using the System allocator and observing its behavior during element additions. Note that a vector of a zero-sized type will always over-allocate to usize::MAX. ```rust #![feature(allocator_api)] use std::alloc.System; let mut vec = Vec::with_capacity_in(10, System); // The vector contains no items, even though it has capacity for more assert_eq!(vec.len(), 0); assert!(vec.capacity() >= 10); // These are all done without reallocating... for i in 0..10 { vec.push(i); } assert_eq!(vec.len(), 10); assert!(vec.capacity() >= 10); // ...but this may make the vector reallocate vec.push(11); assert_eq!(vec.len(), 11); assert!(vec.capacity() >= 11); // A vector of a zero-sized type will always over-allocate, since no // allocation is necessary let vec_units = Vec::<(), System>::with_capacity_in(10, System); assert_eq!(vec_units.capacity(), usize::MAX); ``` -------------------------------- ### Get Vec Length Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Returns the number of elements currently in the vector. ```rust let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### RegionFileLoader Methods Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.RegionFileLoader.html Methods for initializing the loader and interacting with region files. ```APIDOC ## new(region_dir: PathBuf) ### Description Creates a new RegionFileLoader instance pointing to the specified directory. ### Parameters - **region_dir** (PathBuf) - Required - The directory path containing region files. ## has_region(x: RCoord, z: RCoord) ### Description Checks if a region file exists for the given coordinates. ### Parameters - **x** (RCoord) - Required - The X coordinate of the region. - **z** (RCoord) - Required - The Z coordinate of the region. ### Response - **bool** - Returns true if the region exists, false otherwise. ## region(x: RCoord, z: RCoord) ### Description Retrieves a specific region file. Returns Ok(None) if the region does not exist. ### Parameters - **x** (RCoord) - Required - The X coordinate of the region. - **z** (RCoord) - Required - The Z coordinate of the region. ### Response - **LoaderResult>>** - The region object or None. ## list() ### Description Lists all regions available to this loader. ### Response - **LoaderResult>** - A list of coordinate pairs for available regions. ``` -------------------------------- ### Get Chunk Y Range Source: https://docs.rs/fastanvil/0.32.0/fastanvil/enum.JavaChunk.html Returns the valid range of Y values for this chunk. ```rust fn y_range(&self) -> Range ``` -------------------------------- ### Vec with Custom Allocator Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Demonstrates creating a Vec with a custom allocator and converting it back to its components. ```rust #![feature(allocator_api)] use std::alloc::System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr.cast::(); Vec::from_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` -------------------------------- ### TopShadeRenderer::new Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.TopShadeRenderer.html Constructs a new TopShadeRenderer instance. ```APIDOC ## TopShadeRenderer::new ### Description Constructs a new `TopShadeRenderer` instance. ### Method `pub fn new(palette: &'a P, mode: HeightMode) -> Self` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Self** (TopShadeRenderer) - A new instance of TopShadeRenderer. #### Response Example None ``` -------------------------------- ### Vec::with_capacity_in Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Constructs a new, empty Vec with a specified initial capacity and allocator. This is a nightly-only experimental API. ```APIDOC ## POST /vec/with_capacity_in ### Description Constructs a new, empty `Vec` with at least the specified capacity and the provided allocator. The vector will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is zero, the vector will not allocate. It is important to note that although the returned vector has the minimum _capacity_ specified, the vector will have a zero _length_. For an explanation of the difference between length and capacity, see _Capacity and reallocation_. If it is important to know the exact allocated capacity of a `Vec`, always use the `capacity` method after construction. For `Vec` where `T` is a zero-sized type, there will be no allocation and the capacity will always be `usize::MAX`. ### Method POST ### Endpoint /vec/with_capacity_in ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **capacity** (usize) - Required - The minimum capacity for the new vector. - **alloc** (A) - Required - The allocator to use for the vector. ### Request Example ```json { "capacity": 10, "alloc": "System" } ``` ### Response #### Success Response (200) - **Vec** - A new, empty vector with the specified capacity and allocator. #### Response Example ```json { "vec": [] } ``` ##### §Panics Panics if the new capacity exceeds `isize::MAX` _bytes_. ``` -------------------------------- ### Get Type ID Source: https://docs.rs/fastanvil/0.32.0/fastanvil/enum.JavaChunk.html Returns the TypeId of the current type. This is part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Renderer Constructor Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/struct.Renderer.html Initializes a new Renderer instance. Requires HashMaps for blockstates, models, and textures. ```rust pub fn new( blockstates: HashMap, models: HashMap, textures: HashMap, ) -> Self ``` -------------------------------- ### Get Immutable Slice of Vec Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Extracts a slice containing the entire vector. Equivalent to `&s[..]`. ```rust use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap(); ``` -------------------------------- ### Get Top Texture Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/struct.Renderer.html Retrieves the top texture for a given block ID and encoded properties. ```APIDOC ## fn get_top ### Description Retrieves the top texture associated with a specific block ID and its encoded properties. ### Parameters - **id** (str) - Required - The block identifier. - **encoded_props** (str) - Required - The encoded properties string for the block. ### Response - **Result** - Returns the texture or an error if the operation fails. ``` -------------------------------- ### RegionLoader.list Method Source: https://docs.rs/fastanvil/0.32.0/fastanvil/trait.RegionLoader.html Lists all regions that the loader can return. Implementations must provide this to allow efficient processing of regions. ```rust fn list(&self) -> LoaderResult>; ``` -------------------------------- ### Get Immutable Chunk Reference Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.RegionMap.html Provides immutable access to a specific chunk within the RegionMap. ```rust pub fn chunk(&self, x: CCoord, z: CCoord) -> &[T]> ``` -------------------------------- ### Get Mutable Chunk Reference Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.RegionMap.html Provides mutable access to a specific chunk within the RegionMap. ```rust pub fn chunk_mut(&mut self, x: CCoord, z: CCoord) -> &mut [T]> ``` -------------------------------- ### Result Implementations Source: https://docs.rs/fastanvil/0.32.0/fastanvil/type.Result.html Provides documentation for various implementations of the Result type, showcasing different methods and their usage. ```APIDOC ## Implementations ### `impl Result<&T, E>` #### `pub const fn copied(self) -> Result` Maps a `Result<&T, E>` to a `Result` by copying the contents of the `Ok` part. ##### Examples ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` #### `pub fn cloned(self) -> Result` Maps a `Result<&T, E>` to a `Result` by cloning the contents of the `Ok` part. ##### Examples ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ### `impl Result<&mut T, E>` #### `pub const fn copied(self) -> Result` Maps a `Result<&mut T, E>` to a `Result` by copying the contents of the `Ok` part. ##### Examples ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` #### `pub fn cloned(self) -> Result` Maps a `Result<&mut T, E>` to a `Result` by cloning the contents of the `Ok` part. ##### Examples ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ### `impl Result, E>` #### `pub const fn transpose(self) -> Option>` Transposes a `Result` of an `Option` into an `Option` of a `Result`. `Ok(None)` will be mapped to `None`. `Ok(Some(_))` and `Err(_)` will be mapped to `Some(Ok(_))` and `Some(Err(_))`. ##### Examples ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` ### `impl Result, E>` #### `pub const fn flatten(self) -> Result` Converts from `Result, E>` to `Result`. ##### Examples ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` Flattening only removes one level of nesting at a time: ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` ### `impl Result` #### `pub const fn is_ok(&self) -> bool` Returns `true` if the result is `Ok`. ##### Examples ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` #### `pub fn is_ok_and(self, f: F) -> bool` where F: FnOnce(T) -> bool Returns `true` if the result is `Ok` and the value inside of it matches a predicate. ##### Examples ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` #### `pub const fn is_err(&self) -> bool` Returns `true` if the result is `Err`. ##### Examples ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` #### `pub fn is_err_and(self, f: F) -> bool` where F: FnOnce(E) -> bool Returns `true` if the result is `Err` and the value inside of it matches a predicate. ``` -------------------------------- ### Create Vec with Capacity and Allocator (Nightly) Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Constructs a new, empty Vec with a specified initial capacity and allocator. Returns an error if capacity is too large or allocation fails. ```APIDOC ## pub fn try_with_capacity_in( capacity: usize, alloc: A, ) -> Result, TryReserveError> ### Description Constructs a new, empty `Vec` with at least the specified capacity with the provided allocator. The vector will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is zero, the vector will not allocate. ### Method Associated function ### Endpoint N/A (function call) ### Parameters - **capacity** (usize) - The minimum initial capacity for the vector. - **alloc** (A) - The allocator to be used for this vector. ### Request Example ```rust #![feature(allocator_api)] use std::alloc::System; let result: Result, _> = Vec::try_with_capacity_in(10, System); ``` ### Response - **Ok(Vec)** - A new vector with the specified capacity and allocator. - **Err(TryReserveError)** - An error if the capacity exceeds `isize::MAX` bytes or if the allocator reports failure. ``` -------------------------------- ### Create Vec with capacity (experimental) Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Constructs a new, empty Vec with at least the specified capacity, returning a Result to handle potential allocation errors. This is a nightly-only experimental API. ```rust pub fn try_with_capacity(capacity: usize) -> Result, TryReserveError> ``` -------------------------------- ### Get Mutable Slice of Vec Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Extracts a mutable slice of the entire vector. Equivalent to `&mut s[..]`. ```rust use std::io::{self, Read}; let mut buffer = vec![0; 3]; io::repeat(0b101).read_exact(buffer.as_mut_slice()).unwrap(); ``` -------------------------------- ### Lz4DecoderWrapper Initialization Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.Lz4DecoderWrapper.html Creates a new instance of Lz4DecoderWrapper which wraps a writer. ```APIDOC ## Lz4DecoderWrapper::new ### Description Creates a new Lz4DecoderWrapper instance that writes to the provided writer. ### Parameters #### Request Body - **write_to** (W: Write) - Required - The writer to which the decompressed data will be written. ``` -------------------------------- ### Unwrap Err value Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Result.html Use `unwrap_err()` to get the contained `Err` value. Panics if the value is an `Ok`. ```rust let x: Result = Ok(2); x.unwrap_err(); // panics with `2` ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### Implementations for Result, E> Source: https://docs.rs/fastanvil/0.32.0/fastanvil/type.LoaderResult.html Provides implementations for Result, E>, including the `transpose` method. ```APIDOC ### impl Result, E> #### pub const fn transpose(self) -> Option> Transposes a `Result` of an `Option` into an `Option` of a `Result`. `Ok(None)` will be mapped to `None`. `Ok(Some(_))` and `Err(_)` will be mapped to `Some(Ok(_))` and `Some(Err(_))`. ##### §Examples ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` ``` -------------------------------- ### Unwrap Ok value Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Result.html Use `unwrap()` to get the contained `Ok` value. Panics if the value is an `Err`. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` -------------------------------- ### Resize Vec with Closure Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Shows how to resize a vector in-place using `resize_with`. New elements are generated by a provided closure. If `new_len` is greater than `len`, the vector is extended; otherwise, it's truncated. ```rust let mut vec = vec![1, 2, 3]; vec.resize_with(5, Default::default); assert_eq!(vec, [1, 2, 3, 0, 0]); ``` ```rust let mut vec = vec![]; let mut p = 1; vec.resize_with(4, || { p *= 2; p }); assert_eq!(vec, [2, 4, 8, 16]); ``` -------------------------------- ### Get Chunk Status Source: https://docs.rs/fastanvil/0.32.0/fastanvil/enum.JavaChunk.html Retrieves the status of the chunk as a string. This method is part of the Chunk trait implementation for JavaChunk. ```rust fn status(&self) -> String ``` -------------------------------- ### Vec Capacity Check Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Shows how to check the capacity of a Vec and asserts that it meets a minimum requirement. ```rust let mut vec: Vec = Vec::with_capacity(10); vec.push(42); assert!(vec.capacity() >= 10); ``` -------------------------------- ### CloneToUninit Trait Implementation Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.Region.html Details the nightly-only experimental blanket implementation of `CloneToUninit` for types implementing `Clone`. ```APIDOC ## impl CloneToUninit for T ### Description Nightly-only experimental blanket implementation of the `CloneToUninit` trait for types implementing `Clone`. ### Method `clone_to_uninit` ### Endpoint N/A (Trait Implementation) ### Parameters - **dest** (*mut u8) - The destination pointer to copy the data to. ### Request Body N/A ### Response N/A (Unsafe function) ### Response Example N/A ``` -------------------------------- ### Get Top Texture Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/struct.Renderer.html Retrieves the top texture for a given ID and encoded properties. Returns a Result containing the Texture or an error. ```rust fn get_top(&mut self, id: &str, encoded_props: &str) -> Result ``` -------------------------------- ### Iterator Adapters: take, scan, flat_map, flatten, map_windows, fuse, inspect, by_ref Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.RegionIter.html These methods adapt existing iterators to provide new iteration behaviors. ```APIDOC ## Iterator Adapters ### `take(n)` Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### `scan(initial_state, f)` An iterator adapter which, like `fold`, holds internal state, but unlike `fold`, produces a new iterator. ### `flat_map(f)` Creates an iterator that works like map, but flattens nested structure. ### `flatten()` Creates an iterator that flattens nested structure. ### `map_windows(f, N)` Calls the given function `f` for each contiguous window of size `N` over `self` and returns an iterator over the outputs of `f`. Like `slice::windows()`, the windows during mapping overlap as well. (Nightly-only experimental API) ### `fuse()` Creates an iterator which ends after the first `None`. ### `inspect(f)` Does something with each element of an iterator, passing the value on. ### `by_ref()` Creates a “by reference” adapter for this instance of `Iterator`. ``` -------------------------------- ### Safely get Err value (nightly) Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Result.html The `into_err()` method returns the contained `Err` value and is guaranteed not to panic. This is a nightly-only experimental API. ```rust fn only_bad_news() -> Result { Err("Oops, it failed".into()) } let error: String = only_bad_news().into_err(); println!("{error}"); ``` -------------------------------- ### Get Block at Coordinate Source: https://docs.rs/fastanvil/0.32.0/fastanvil/enum.JavaChunk.html Retrieves the block at the specified X, Y, and Z coordinates. Returns None if the section of the chunk at the given height is not present. ```rust fn block(&self, x: usize, y: isize, z: usize) -> Option<&Block> ``` -------------------------------- ### Implementations for Result<&mut T, E> Source: https://docs.rs/fastanvil/0.32.0/fastanvil/type.LoaderResult.html Provides implementations for Result<&mut T, E>, including `copied` and `cloned` methods. ```APIDOC ### impl Result<&mut T, E> #### pub const fn copied(self) -> Result where T: Copy, Maps a `Result<&mut T, E>` to a `Result` by copying the contents of the `Ok` part. ##### §Examples ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` #### pub fn cloned(self) -> Result where T: Clone, Maps a `Result<&mut T, E>` to a `Result` by cloning the contents of the `Ok` part. ##### §Examples ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ``` -------------------------------- ### Get Biome at Coordinate Source: https://docs.rs/fastanvil/0.32.0/fastanvil/enum.JavaChunk.html Retrieves the biome at the specified X, Y, and Z coordinates. Returns None if the section of the chunk at the given height is not present. ```rust fn biome(&self, x: usize, y: isize, z: usize) -> Option ``` -------------------------------- ### Structs in pre13 Module Source: https://docs.rs/fastanvil/0.32.0/fastanvil/pre13/index.html Overview of the key structures defined in the pre13 module for representing Minecraft chunk data. ```APIDOC ## Structs ### JavaChunk A Minecraft chunk. ### Level A level describes the contents of the chunk in the world. ### Pre13Section A vertical section of a chunk (ie a 16x16x16 block cube), for before 1.13. ### RawBlock Raw block representation: block_id:data_value ``` -------------------------------- ### Create Vec from Raw Parts with Custom Allocator (Nightly) Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Use `from_raw_parts_in` to create a Vec from a raw pointer, length, capacity, and a specified allocator. ```rust #![feature(allocator_api)] let ptr = std::ptr::null_mut(); let len = 0; let cap = 10; let vec: Vec = unsafe { Vec::from_raw_parts_in(ptr, len, cap, System) }; ``` -------------------------------- ### ChunkLocation Struct Definition Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.ChunkLocation.html Defines the structure for a chunk's location within a region file, specifying its starting offset and size in sectors. ```rust pub struct ChunkLocation { pub offset: u64, pub sectors: u64, } ``` -------------------------------- ### TryFrom and TryInto Trait Implementations Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.Region.html Covers the blanket implementations for `TryFrom` for `T` and `TryInto` for `T`. ```APIDOC ## impl TryFrom for T ### Description Blanket implementation of the `TryFrom` trait for type `T`, provided `U` implements `Into`. ### Method `try_from` ### Endpoint N/A (Trait Implementation) ### Parameters - **value** (U) - The value to convert. ### Request Body N/A ### Response #### Success Response (200) - **Result** (Result) - The result of the conversion. ### Response Example N/A (Method Call) ## impl TryInto for T ### Description Blanket implementation of the `TryInto` trait for type `T`, provided `U` implements `TryFrom`. ### Method `try_into` ### Endpoint N/A (Trait Implementation) ### Parameters N/A ### Request Body N/A ### Response #### Success Response (200) - **Result>::Error>** (Result>::Error>) - The result of the conversion. ### Response Example N/A (Method Call) ``` -------------------------------- ### Expect Err value with custom panic message Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Result.html Use `expect_err()` to get the contained `Err` value. Panics with a custom message if the value is an `Ok`. ```rust let x: Result = Ok(10); x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10` ``` -------------------------------- ### Construct Vec with Capacity and Allocator Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Constructs a new, empty `Vec` with at least the specified capacity and a provided allocator. This is a nightly-only experimental API. ```rust pub const fn with_capacity_in(capacity: usize, alloc: A) -> Vec ``` -------------------------------- ### Implement Iterator for StatesIter Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.StatesIter.html Core iterator functionality for StatesIter. This includes methods for advancing the iterator, getting the next item, and determining size hints. ```rust impl<'a> Iterator for StatesIter<'a> ``` ```rust type Item = usize ``` ```rust fn next(&mut self) -> Option ``` ```rust fn size_hint(&self) -> (usize, Option) ``` -------------------------------- ### From and Into Trait Implementations Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.Region.html Describes the blanket implementations for `From` for `T` and `Into` for `T` where `U` implements `From`. ```APIDOC ## impl From for T ### Description Blanket implementation of the `From` trait for type `T` itself. ### Method `from` ### Endpoint N/A (Trait Implementation) ### Parameters - **t** (T) - The value to convert. ### Request Body N/A ### Response #### Success Response (200) - **T** (T) - The argument unchanged. ### Response Example N/A (Method Call) ## impl Into for T ### Description Blanket implementation of the `Into` trait for type `T`, provided `U` implements `From`. ### Method `into` ### Endpoint N/A (Trait Implementation) ### Parameters N/A ### Request Body N/A ### Response #### Success Response (200) - **U** (U) - The result of `U::from(self)`. ### Response Example N/A (Method Call) ``` -------------------------------- ### Implement ExactSizeIterator for StatesIter Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.StatesIter.html Provides exact size information for the StatesIter iterator. This includes methods to get the remaining length and check if the iterator is empty. ```rust impl<'a> ExactSizeIterator for StatesIter<'a> ``` ```rust fn len(&self) -> usize ``` ```rust fn is_empty(&self) -> bool ``` -------------------------------- ### SectionLike Trait Definition Source: https://docs.rs/fastanvil/0.32.0/fastanvil/trait.SectionLike.html Defines the SectionLike trait with required methods for checking terminators and getting the y-coordinate. Implementations are provided for Pre13Section, Pre18Section, and Section. ```rust pub trait SectionLike { // Required methods fn is_terminator(&self) -> bool; fn y(&self) -> i8; } ``` -------------------------------- ### load_rendered_palette Source: https://docs.rs/fastanvil/0.32.0/fastanvil/fn.load_rendered_palette.html Loads a prepared rendered palette from a reader, typically used with palette.tar.gz files. ```APIDOC ## Function load_rendered_palette ### Description Loads a prepared rendered palette. This is intended for use with the palette.tar.gz file found in the fastnbt project repository. ### Signature `pub fn load_rendered_palette(palette: impl Read) -> Result` ### Parameters - **palette** (impl Read) - Required - A reader providing the palette data. ### Response - **Result** - Returns a RenderedPalette on success, or a PaletteError if the loading fails. ``` -------------------------------- ### Chain fallible operations with and_then Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Result.html Use and_then to chain operations that return a Result. The provided examples demonstrate handling successful results and error propagation. ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Region Initialization and Reading Source: https://docs.rs/fastanvil/0.32.0/fastanvil/struct.Region.html Methods for loading a region from a stream and reading specific chunk data. ```APIDOC ## from_stream ### Description Loads a region from an existing stream (e.g., File or Cursor). Assumes a seek of zero is the start of the region. ### Parameters #### Request Body - **stream** (S: Read + Seek) - Required - The underlying stream to read from. ## read_chunk ### Description Reads the chunk located at the specified coordinates. Returns uncompressed NBT data. ### Parameters #### Path Parameters - **x** (usize) - Required - Chunk X coordinate (0-31). - **z** (usize) - Required - Chunk Z coordinate (0-31). ### Response #### Success Response (200) - **Option>** - The uncompressed NBT data of the chunk, or None if the chunk does not exist. ``` -------------------------------- ### Fastanvil Module Documentation Source: https://docs.rs/fastanvil/0.32.0/fastanvil/complete/index.html Overview of the fastanvil module, including its structs and features. ```APIDOC ## Module: fastanvil This module provides functionality for working with anvil files. ### Structs #### Chunk A struct representing a chunk within an anvil file. Further details about its fields and methods are not provided in the source text. ``` -------------------------------- ### Unwrap or return default Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Result.html Use `unwrap_or_default()` to get the contained `Ok` value or the default value if it's an `Err`. Requires the error type to implement `Default`. ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse().unwrap_or_default(); let bad_year = bad_year_from_input.parse().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` -------------------------------- ### Vec Implementations for Texture Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Details common Vec methods applicable to Texture, such as new(), with_capacity(), try_with_capacity(), and from_raw_parts(). ```APIDOC ## Implementations ### impl Vec #### pub const fn new() -> Vec Constructs a new, empty `Vec`. ##### §Examples ```rust let mut vec: Vec = Vec::new(); ``` #### pub fn with_capacity(capacity: usize) -> Vec Constructs a new, empty `Vec` with at least the specified capacity. ##### §Panics Panics if the new capacity exceeds `isize::MAX` _bytes_. ##### §Examples ```rust let mut vec = Vec::with_capacity(10); assert_eq!(vec.len(), 0); assert!(vec.capacity() >= 10); for i in 0..10 { vec.push(i); } assert_eq!(vec.len(), 10); assert!(vec.capacity() >= 10); vec.push(11); assert_eq!(vec.len(), 11); assert!(vec.capacity() >= 11); let vec_units = Vec::<()>::with_capacity(10); assert_eq!(vec_units.capacity(), usize::MAX); ``` #### pub fn try_with_capacity(capacity: usize) -> Result, TryReserveError> Constructs a new, empty `Vec` with at least the specified capacity. ##### §Errors Returns an error if the capacity exceeds `isize::MAX` _bytes_ , or if the allocator reports allocation failure. #### pub unsafe fn from_raw_parts( ptr: *mut T, length: usize, capacity: usize, ) -> Vec Creates a `Vec` directly from a pointer, a length, and a capacity. ``` -------------------------------- ### Deconstruct and Reconstruct Vec Source: https://docs.rs/fastanvil/0.32.0/fastanvil/tex/type.Texture.html Use `into_raw_parts` to get the pointer, length, and capacity of a Vec. This is useful for manual memory manipulation before reconstructing the Vec using `Vec::from_raw_parts`. ```rust use std::ptr; let v = vec![1, 2, 3]; // Deconstruct the vector into parts. let (p, len, cap) = v.into_raw_parts(); unsafe { // Overwrite memory with 4, 5, 6 for i in 0..len { ptr::write(p.add(i), 4 + i); } // Put everything back together into a Vec let rebuilt = Vec::from_raw_parts(p, len, cap); assert_eq!(rebuilt, [4, 5, 6]); } ```