tilecodec: fix all cargo check and clippy warnings and test errors
- Commit
a4c5dd91bac2c676e2f314e82bd60474d70a7897- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 14:19 UTC (18 days ago)
- Parents
d6e7638
Writer tests now build via a self dev-dependency enabling the write feature, so blocked.rs (zstd BlockedStreamWriter) and mamaps::write integration tests compile and run under plain cargo test while the default Android lib stays read-only. Type aliases, redundant cast/mut removals, unused re-export removals, Spill::append cfg(test)-gated. Verified in-crate: check/clippy --all-targets 0 warnings, cargo test 202 lib + 20 integration passed.
Diff
Cargo.lock
diff --git a/Cargo.lock b/Cargo.lockindex 815310cee4..dabd3c6dc8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5510,6 +5510,7 @@ version = "0.1.0" dependencies = [ "miniz_oxide 0.8.9", "ruzstd",+ "tilecodec", "zstd-rs", ]
library/tilecodec/src/main/rust/Cargo.toml
diff --git a/library/tilecodec/src/main/rust/Cargo.toml b/library/tilecodec/src/main/rust/Cargo.tomlindex 2237420221..3a79d1a435 100644--- a/library/tilecodec/src/main/rust/Cargo.toml+++ b/library/tilecodec/src/main/rust/Cargo.toml@@ -49,3 +49,9 @@ ruzstd.workspace = true # Pure-Rust zstd encoder, host-side only (writer): v9 bodies. Optional so the # cdylib never links it — Android reads archives, it never writes one. zstd-rs = { workspace = true, optional = true }++[dev-dependencies]+# Tests build archives, so they need the writer the Android cdylib never links.+# Self dev-dependency (same pattern as :library:map and maps) enables `write`+# only for test targets; the default lib build stays read-only.+tilecodec = { path = ".", features = ["write"] }
library/tilecodec/src/main/rust/src/blocked.rs
diff --git a/library/tilecodec/src/main/rust/src/blocked.rs b/library/tilecodec/src/main/rust/src/blocked.rsindex f3d5328c07..34d1c6d6a1 100644--- a/library/tilecodec/src/main/rust/src/blocked.rs+++ b/library/tilecodec/src/main/rust/src/blocked.rs@@ -529,7 +529,6 @@ impl BlockedStreamWriter { /// Append whole records. Must be a multiple of the stride. pub fn push(&mut self, records: &[u8]) -> std::io::Result<()> {- use std::io::Write as _; assert_eq!(records.len() % self.record_len, 0, "whole records only"); self.block.extend_from_slice(records); self.records += (records.len() / self.record_len) as u64;@@ -692,8 +691,8 @@ mod tests { let mut out = Vec::with_capacity(n * len); for i in 0..n { let mut rec = Vec::with_capacity(12.max(len));- rec.extend_from_slice(&((350_000_000 + i as i32 * 37) as i32).to_le_bytes());- rec.extend_from_slice(&((-1_200_000_000 + i as i32 * 11) as i32).to_le_bytes());+ rec.extend_from_slice(&(350_000_000 + i as i32 * 37).to_le_bytes());+ rec.extend_from_slice(&(-1_200_000_000 + i as i32 * 11).to_le_bytes()); rec.extend_from_slice(&(i as u32 * 3).to_le_bytes()); rec.resize(len, 0); out.extend_from_slice(&rec);
library/tilecodec/src/main/rust/src/mamaps/body.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/body.rs b/library/tilecodec/src/main/rust/src/mamaps/body.rsindex b98f1f9327..03bc921b8b 100644--- a/library/tilecodec/src/main/rust/src/mamaps/body.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/body.rs@@ -78,5 +78,4 @@ pub use model::{ ROOF_SKILLION, }; pub use emit::{Scratch, serialize, serialize_into, serialize_into_v10, serialize_into_v11, serialize_into_v12};-pub(crate) use codec::parse_layer; pub(crate) use tables::align4;
library/tilecodec/src/main/rust/src/mamaps/body/codec.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/body/codec.rs b/library/tilecodec/src/main/rust/src/mamaps/body/codec.rsindex 1a68bb81b6..7970c9c9b8 100644--- a/library/tilecodec/src/main/rust/src/mamaps/body/codec.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/body/codec.rs@@ -1,4 +1,4 @@-use super::consts::{BODY_FLAG_BUILDING_TABLE, BODY_FLAG_EXTENDED_COUNTS, BODY_FLAG_HEIGHTMAP, BODY_FLAG_ID_TABLE, BODY_FLAG_LANE_TABLE, BODY_FLAG_NAME_TABLE, BODY_FLAG_REGION_LINKS, BODY_FLAG_ROAD_LANES, BODY_HEADER_LEN, FEATURE_RECORD_LEN, GEOM_LINE, GEOM_POINT, GEOM_POLYGON, KNOWN_BODY_FLAGS, KNOWN_FEATURE_FLAGS, LAYER_INDEX_LEN, PART_ENTRY_LEN, PART_ENTRY_V10_LEN, WINDING_HOLE, WINDING_OUTER};+use super::consts::{BODY_FLAG_BUILDING_TABLE, BODY_FLAG_EXTENDED_COUNTS, BODY_FLAG_HEIGHTMAP, BODY_FLAG_ID_TABLE, BODY_FLAG_LANE_TABLE, BODY_FLAG_NAME_TABLE, BODY_FLAG_REGION_LINKS, BODY_FLAG_ROAD_LANES, BODY_HEADER_LEN, FEATURE_RECORD_LEN, GEOM_LINE, GEOM_POINT, GEOM_POLYGON, KNOWN_BODY_FLAGS, KNOWN_FEATURE_FLAGS, LAYER_INDEX_LEN, PART_ENTRY_LEN, WINDING_HOLE, WINDING_OUTER}; use super::model::{Body, BuildingAttrs, Carriageway, Feature, LaneTurns, Layer, NAME_NONE, Part}; use super::tables::{align4, parse_carriageways, parse_heightmap, parse_ids, parse_lanes, parse_names, parse_region_links, payloads_end}; use super::tables_extra::{parse_buildings, parse_sparse_buildings, parse_sparse_carriageways, parse_sparse_lanes};
library/tilecodec/src/main/rust/src/mamaps/body/tables.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/body/tables.rs b/library/tilecodec/src/main/rust/src/mamaps/body/tables.rsindex c6f10c0ea2..b9e396b07a 100644--- a/library/tilecodec/src/main/rust/src/mamaps/body/tables.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/body/tables.rs@@ -2,6 +2,9 @@ use super::consts::{BODY_HEADER_LEN, CARRIAGEWAY_RECORD_LEN, LAYER_INDEX_LEN}; use super::model::{Carriageway, Heightmap, LaneTurns, Layer, MarkingConvention}; use crate::proto::{Result, err}; +/// A per-layer table: `(layer id, records for that layer)` entries, ascending by layer id.+pub(crate) type LayerTable<T> = Vec<(u8, Vec<T>)>;+ /// The unaligned end of the last layer payload, as the index declares it. /// /// Payload offsets and lengths live in the body's layer index (`index_end` is where the index@@ -120,7 +123,7 @@ pub(crate) fn align4(at: usize) -> usize { /// a layer the body actually carries, entries must be ascending and distinct by layer id, and a /// layer's id vector must be exactly as long as its feature vector. A short or long vector would /// silently misattribute every id after the first mismatch.-pub(crate) fn parse_ids(buf: &[u8], layers: &[Layer]) -> Result<(Vec<(u8, Vec<u64>)>, usize)> {+pub(crate) fn parse_ids(buf: &[u8], layers: &[Layer]) -> Result<(LayerTable<u64>, usize)> { if buf.len() < 4 { return err("a .mamaps id table ends before its count"); }@@ -214,7 +217,7 @@ pub fn serialize_ids(ids: &[(u8, Vec<u64>)], out: &mut Vec<u8>) { pub(crate) fn parse_region_links( buf: &[u8], layers: &[Layer],-) -> Result<(Vec<(u8, Vec<u64>)>, usize)> {+) -> Result<(LayerTable<u64>, usize)> { if buf.len() < 4 { return err("a .mamaps region-link table ends before its count"); }@@ -308,7 +311,7 @@ pub fn serialize_region_links(links: &[(u8, Vec<u64>)], out: &mut Vec<u8>) { /// The same shape and validation as [`parse_ids`]: an entry must name a layer the body carries, /// entries ascend and are distinct by layer id, and a layer's turn vector is exactly as long as /// its feature vector — a mismatch would misattribute every feature's lanes after the first.-pub(crate) fn parse_lanes(buf: &[u8], layers: &[Layer]) -> Result<(Vec<(u8, Vec<LaneTurns>)>, usize)> {+pub(crate) fn parse_lanes(buf: &[u8], layers: &[Layer]) -> Result<(LayerTable<LaneTurns>, usize)> { if buf.len() < 4 { return err("a .mamaps turn-lane table ends before its count"); }@@ -420,7 +423,7 @@ pub fn serialize_lanes(turn_lanes: &[(u8, Vec<LaneTurns>)], out: &mut Vec<u8>) { pub(crate) fn parse_carriageways( buf: &[u8], layers: &[Layer],-) -> Result<(Vec<(u8, Vec<Carriageway>)>, MarkingConvention, usize)> {+) -> Result<(LayerTable<Carriageway>, MarkingConvention, usize)> { if buf.len() < 8 { return err("a .mamaps carriageway table ends before its header"); }
library/tilecodec/src/main/rust/src/mamaps/body/tables_extra.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/body/tables_extra.rs b/library/tilecodec/src/main/rust/src/mamaps/body/tables_extra.rsindex 4db79fef85..2ff4ec34c7 100644--- a/library/tilecodec/src/main/rust/src/mamaps/body/tables_extra.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/body/tables_extra.rs@@ -2,7 +2,7 @@ use super::model::{ BUILDING_ATTRS_LEN, BuildingAttrs, Carriageway, LaneTurns, Layer, MarkingConvention, ROOF_ORIENT_MAX, ROOF_SHAPE_MAX, };-use super::tables::align4;+use super::tables::{LayerTable, align4}; use crate::proto::{Result, err}; /// Parse the S3DB building attribute table: the same framing as [`super::tables::parse_ids`] — a `u32` entry@@ -15,7 +15,7 @@ use crate::proto::{Result, err}; /// is exactly as long as its feature vector — a mismatch would misattribute every building's /// height after the first. `roof_shape`, `roof_orientation` and the reserved bytes are checked so a /// corrupt record fails here rather than extruding a wrong shape on device.-pub(crate) fn parse_buildings(buf: &[u8], layers: &[Layer]) -> Result<(Vec<(u8, Vec<BuildingAttrs>)>, usize)> {+pub(crate) fn parse_buildings(buf: &[u8], layers: &[Layer]) -> Result<(LayerTable<BuildingAttrs>, usize)> { if buf.len() < 4 { return err("a .mamaps building table ends before its count"); }@@ -143,7 +143,7 @@ pub fn serialize_buildings(buildings: &[(u8, Vec<BuildingAttrs>)], out: &mut Vec pub(crate) fn parse_sparse_lanes( buf: &[u8], layers: &[Layer],-) -> Result<(Vec<(u8, Vec<LaneTurns>)>, usize)> {+) -> Result<(LayerTable<LaneTurns>, usize)> { if buf.len() < 4 { return err("a .mamaps sparse turn-lane table ends before its count"); }@@ -267,7 +267,7 @@ pub fn serialize_sparse_lanes(turn_lanes: &[(u8, Vec<LaneTurns>)], out: &mut Vec pub(crate) fn parse_sparse_carriageways( buf: &[u8], layers: &[Layer],-) -> Result<(Vec<(u8, Vec<Carriageway>)>, MarkingConvention, usize)> {+) -> Result<(LayerTable<Carriageway>, MarkingConvention, usize)> { if buf.len() < 8 { return err("a .mamaps sparse carriageway table ends before its header"); }@@ -415,7 +415,7 @@ fn pack_attrs(a: &BuildingAttrs) -> u8 { pub(crate) fn parse_sparse_buildings( buf: &[u8], layers: &[Layer],-) -> Result<(Vec<(u8, Vec<BuildingAttrs>)>, usize)> {+) -> Result<(LayerTable<BuildingAttrs>, usize)> { use super::model::{ROOF_ORIENT_ACROSS, ROOF_ORIENT_ALONG}; if buf.len() < 4 { return err("a .mamaps sparse building table ends before its count");
library/tilecodec/src/main/rust/src/mamaps/body/tests.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/body/tests.rs b/library/tilecodec/src/main/rust/src/mamaps/body/tests.rsindex 1e2d67c2b3..88d6566bc8 100644--- a/library/tilecodec/src/main/rust/src/mamaps/body/tests.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/body/tests.rs@@ -1,6 +1,8 @@ use super::*; use crate::mamaps::dict; +type BodyMutator = fn(&mut Vec<u8>);+ /// A tile with one polygon carrying a hole and one road, which between them exercise every /// field the format has. fn sample() -> Body {@@ -311,7 +313,7 @@ fn a_corrupt_body_is_refused_rather_than_decoded() { assert!(Body::parse(&good[..BODY_HEADER_LEN - 1]).is_err(), "shorter than the header"); assert!(Body::parse(&good[..good.len() - 4]).is_err(), "declares more than it is"); - let cases: &[(&str, fn(&mut Vec<u8>))] = &[+ let cases: &[(&str, BodyMutator)] = &[ ("bad magic", |b| b[0] = b'X'), ("a newer body version", |b| b[3] = 99), ("a zero extent", |b| b[8..10].copy_from_slice(&0u16.to_le_bytes())),
library/tilecodec/src/main/rust/src/mamaps/header/parse.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/header/parse.rs b/library/tilecodec/src/main/rust/src/mamaps/header/parse.rsindex 2ef7531a62..babe3c5ef4 100644--- a/library/tilecodec/src/main/rust/src/mamaps/header/parse.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/header/parse.rs@@ -185,7 +185,7 @@ impl Header { let sections = [ ("the dictionary", self.dict_offset, self.dict_len as u64), ("the root index", self.root_offset, self.root_len as u64),- ("the leaf index", self.leaf_offset, self.leaf_len as u64),+ ("the leaf index", self.leaf_offset, self.leaf_len), ("the tile data", self.data_offset, self.data_len), ]; for (what, offset, len) in sections {
library/tilecodec/src/main/rust/src/mamaps/header/tests.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/header/tests.rs b/library/tilecodec/src/main/rust/src/mamaps/header/tests.rsindex 800594ff7b..edb6f0a883 100644--- a/library/tilecodec/src/main/rust/src/mamaps/header/tests.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/header/tests.rs@@ -4,6 +4,8 @@ use super::*; +type HeaderMutator = fn(&mut Header);+ /// A header naming sections that do not overlap, in a file big enough to hold them. fn plausible() -> Header { Header {@@ -88,7 +90,7 @@ fn an_unknown_flag_or_a_dirty_reserved_word_is_refused() { /// impossible section has to fail here rather than somewhere uninformative. #[test] fn a_header_whose_sections_do_not_fit_the_file_is_refused() {- let cases: &[(&str, fn(&mut Header))] = &[+ let cases: &[(&str, HeaderMutator)] = &[ ("data past the end", |h| h.data_len = 1 << 40), ("a section inside the header", |h| h.dict_offset = 8), ("the dictionary over the root", |h| h.dict_len = 600),
library/tilecodec/src/main/rust/src/mamaps/read/archive.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/read/archive.rs b/library/tilecodec/src/main/rust/src/mamaps/read/archive.rsindex d14dfd5840..444a614623 100644--- a/library/tilecodec/src/main/rust/src/mamaps/read/archive.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/read/archive.rs@@ -487,7 +487,7 @@ impl<R: RangeReader> MamapsArchive<R> { } let raw_len = root.leaf_entry_count as u64 * index::LEAF_ENTRY_LEN as u64; let stored_len = if root.stored_len == 0 { raw_len } else { root.stored_len as u64 };- if root.leaf_offset + stored_len > self.header.leaf_len as u64 {+ if root.leaf_offset + stored_len > self.header.leaf_len { return err("a .mamaps root entry runs past the leaf section"); } let length = u32::try_from(stored_len)
library/tilecodec/src/main/rust/src/mamaps/read/overlay.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/read/overlay.rs b/library/tilecodec/src/main/rust/src/mamaps/read/overlay.rsindex 5c68d153d1..1d54d51c05 100644--- a/library/tilecodec/src/main/rust/src/mamaps/read/overlay.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/read/overlay.rs@@ -126,10 +126,7 @@ impl<R: RangeReader> TileSource for OverlayArchive<R> { return Ok(None); } for segment in &self.segments {- match segment.tile(z, x, y)? {- some @ Some(_) => return Ok(some),- None => {}- }+ if let some @ Some(_) = segment.tile(z, x, y)? { return Ok(some) } } self.base.tile(z, x, y) }
library/tilecodec/src/main/rust/src/mamaps/tests.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/tests.rs b/library/tilecodec/src/main/rust/src/mamaps/tests.rsindex 0f82b24b3b..b31b7dbf48 100644--- a/library/tilecodec/src/main/rust/src/mamaps/tests.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/tests.rs@@ -1,7 +1,7 @@ use super::*; use crate::mamaps::body::{Feature, Layer, Part, DEFAULT_EXTENT, GEOM_LINE, WINDING_OUTER}; use crate::mamaps::write::{Options, StreamWriter};-use crate::pmtiles::{tile_id, zoom_base};+use crate::pmtiles::tile_id; use crate::proto::Result; use crate::stream::{RangeReader, OPEN_PREFIX_BYTES}; use std::cell::RefCell;@@ -139,7 +139,7 @@ fn wide_body_for(seed: i16) -> Body { #[test] fn a_tile_written_reads_back_exactly() { let bytes = archive(&[(0, 0, 0, 100), (1, 0, 0, 200), (1, 1, 1, 300)], Options::default());- let mut a = open(bytes);+ let a = open(bytes); for (z, x, y, seed) in [(0u8, 0u32, 0u32, 100i16), (1, 0, 0, 200), (1, 1, 1, 300)] { let tile = a.tile(z, x, y).expect("read").expect("present"); assert_eq!(tile, body_for(seed), "z{z}/{x}/{y}");@@ -154,7 +154,7 @@ fn a_tile_written_reads_back_exactly() { #[test] fn a_tile_reads_back_uncompressed_too() { let options = Options { compress: false, ..Options::default() };- let mut a = open(archive(&[(0, 0, 0, 7)], options));+ let a = open(archive(&[(0, 0, 0, 7)], options)); assert!(!a.header.compressed()); assert_eq!(a.tile(0, 0, 0).expect("read").expect("present"), body_for(7)); }@@ -175,7 +175,7 @@ fn open_is_one_request_a_warm_tile_one_a_cold_tile_two_and_never_three() { } } let options = Options { leaf_entry_capacity: 16, ..Options::default() };- let mut a = open(archive(&tiles, options));+ let a = open(archive(&tiles, options)); assert!(a.header.leaf_count > 1, "this test needs several leaves"); assert_eq!( a.reader.requests.borrow().as_slice(),@@ -207,7 +207,7 @@ fn open_is_one_request_a_warm_tile_one_a_cold_tile_two_and_never_three() { /// request, so it poisons that range for every later read. #[test] fn every_read_takes_its_length_from_a_declared_field() {- let mut a = open(archive(&[(0, 0, 0, 1), (1, 0, 0, 2)], Options::default()));+ let a = open(archive(&[(0, 0, 0, 1), (1, 0, 0, 2)], Options::default())); let (leaf_len, leaf_offset) = (a.header.leaf_len, a.header.leaf_offset); a.reader.requests.borrow_mut().clear(); assert!(a.tile(1, 0, 0).expect("read").is_some());@@ -215,7 +215,7 @@ fn every_read_takes_its_length_from_a_declared_field() { assert_eq!(requests.len(), 2); // The leaf: offset and length both from the root entry and the header. assert_eq!(requests[0].0, leaf_offset, "the leaf is where the header says");- assert!(requests[0].1 as u64 <= leaf_len as u64, "and no longer than the section it is in");+ assert!(requests[0].1 as u64 <= leaf_len, "and no longer than the section it is in"); assert_eq!( requests[0].1 as usize % index::LEAF_ENTRY_LEN, 0,@@ -231,7 +231,7 @@ fn every_read_takes_its_length_from_a_declared_field() { fn a_range_that_comes_back_short_is_refused() { let full = archive(&[(0, 0, 0, 1), (1, 0, 0, 2)], Options::default()); let truncated = full[..full.len() - 8].to_vec();- let mut a =+ let a = MamapsArchive::open(Counting { bytes: truncated, requests: RefCell::new(Vec::new()) }) .expect("the prefix is intact, so open still works"); let failure = a.tile(1, 0, 0).expect_err("the last body is cut off");@@ -249,7 +249,7 @@ fn identical_tiles_share_one_body_whether_or_not_they_are_consecutive() { assert_eq!(header.bodies_written, 2, "one distinct z1 body plus z0's"); assert!(header.flags & header::FLAG_RUN_LENGTH_PRESENT != 0, "a run was used"); // And all four still read back.- let mut a = open(bytes);+ let a = open(bytes); for (x, y) in [(0u32, 0u32), (1, 0), (1, 1), (0, 1)] { assert_eq!(a.tile(1, x, y).expect("read").expect("present"), body_for(5)); }@@ -274,7 +274,7 @@ fn a_tile_can_share_a_body_written_for_an_earlier_leaf() { assert_eq!(header.tiles_addressed, 64); assert!(header.bodies_written <= 8, "{} bodies for two shapes", header.bodies_written); assert!(header.leaf_count > 4, "this test needs the repeats to cross leaves");- let mut a = open(bytes);+ let a = open(bytes); for (z, x, y, seed) in &tiles { let tile = a.tile(*z, *x as u32, *y as u32).expect("read").expect("present"); assert_eq!(tile, body_for(*seed), "z{z}/{x}/{y}");@@ -315,7 +315,7 @@ fn content_dedup_confirms_a_candidate_that_has_already_reached_the_scratch_file( assert_eq!(header.bodies_written, DISTINCT as u64, "the second pass stored nothing new"); // And every tile still reads back as itself, which is what confirming against the wrong // bytes would silently break.- let mut a = open(bytes);+ let a = open(bytes); for (id, seed) in &rows { let (z, x, y) = crate::pmtiles::tile_zxy(*id); let tile = a.tile(z, x as u32, y as u32).expect("read").expect("present");
library/tilecodec/src/main/rust/src/mamaps/tests_extra.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/tests_extra.rs b/library/tilecodec/src/main/rust/src/mamaps/tests_extra.rsindex bc843c775f..57238687d3 100644--- a/library/tilecodec/src/main/rust/src/mamaps/tests_extra.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/tests_extra.rs@@ -151,7 +151,7 @@ fn a_root_too_large_for_the_prefix_grows_its_leaves_instead() { let prefix = header::HEADER_LEN as u64 + header.dict_len as u64 + header.root_len as u64; assert!(prefix <= OPEN_PREFIX_BYTES as u64, "the prefix is {prefix} bytes"); // And it still opens in one request and reads back.- let mut a = open(bytes);+ let a = open(bytes); assert_eq!(a.reader.requests.borrow().len(), 1); assert_eq!(a.tile(6, 63, 63).expect("read").expect("present"), body_for(63 * 64 + 63)); }@@ -224,7 +224,6 @@ fn a_zstd_body_decodes_to_the_bytes_it_was_encoded_from() { /// section is smaller than the raw one — while the legacy all-raw layout still opens too. #[test] fn compressed_leaves_round_trip_and_keep_the_prefix_budget() {- use crate::mamaps::header::FLAG_LEAVES_COMPRESSED; use crate::mamaps::index::{LEAF_ENTRY_LEN, ROOT_ENTRY_LEN}; // Enough tiles for several leaves, with repeats so runs and content dedup both fire. let mut tiles: Vec<(u8, u64, u64, i16)> = Vec::new();@@ -267,7 +266,7 @@ fn compressed_leaves_round_trip_and_keep_the_prefix_budget() { } assert!(header.leaf_len < raw_total, "the stored section is smaller than the raw leaves"); // And the whole archive reads back tile-for-tile through the range-reader path.- let mut a = open(bytes);+ let a = open(bytes); assert_eq!(a.reader.requests.borrow().len(), 1, "open is still one request"); for (z, x, y, seed) in &tiles { let tile = a.tile(*z, *x as u32, *y as u32).expect("read").expect("present");@@ -300,7 +299,7 @@ fn raw_leaves_stay_byte_identical_and_still_open() { assert_eq!(c1, c2); // Both open and read on the same reader. for bytes in [raw, c1] {- let mut a = open(bytes);+ let a = open(bytes); assert_eq!(a.tile(2, 3, 3).expect("read").expect("present"), body_for(15)); } }@@ -312,7 +311,8 @@ fn raw_leaves_stay_byte_identical_and_still_open() { /// to the old chunks(capacity) partitioning (NA sha FF312EC...). #[test] fn a_leaf_whose_data_span_would_exceed_u32_max_is_split_and_common_case_stays_byte_identical() {- use crate::mamaps::write::{Pending, Options, StreamWriter};+ use crate::mamaps::write::writer::Pending;+ use crate::mamaps::write::{Options, StreamWriter}; // 1) Common case: all offsets within one capacity chunk and span < u32::MAX // → must yield ceil(N/capacity) leaves, same as old chunks(capacity).@@ -324,7 +324,7 @@ fn a_leaf_whose_data_span_would_exceed_u32_max_is_split_and_common_case_stays_by .map(|i| Pending { tile_id: crate::pmtiles::tile_id(4, (i%32) as u64, (i/32) as u64), offset: i as u64 * 1024, run_length: 1, length: 100 }) .collect(); let split = crate::mamaps::write::StreamWriter::partition_for_test(&entries, cap).expect("partition").expect("split");- let expected_leaves = (n + cap as usize - 1)/ cap as usize;+ let expected_leaves = n.div_ceil(cap as usize); assert_eq!(split.0.len(), expected_leaves, "common case must use count-only split"); assert_eq!(split.1.iter().map(|l| l.len()).sum::<usize>(), n); // Every leaf leaf_offset must be byte-identical to old count-only: leaf_offset = leaf_index * cap*16@@ -382,7 +382,7 @@ fn a_leaf_whose_data_span_would_exceed_u32_max_is_split_and_common_case_stays_by }, names: Vec::new(), ids: Vec::new(), turn_lanes: Vec::new(), buildings: Vec::new(), heightmap: None, carriageways: Vec::new(), convention: None, region_links: Vec::new() }).expect("append"); } let bytes = w.finish().expect("finish"); let hdr = crate::mamaps::Header::parse(&bytes).expect("hdr");- assert_eq!(hdr.leaf_count as usize, (5000+4096-1)/4096);+ assert_eq!(hdr.leaf_count as usize, 5000_usize.div_ceil(4096)); eprintln!("end-to-end: 5000 tiles → leaf_count={} leaf_len={}", hdr.leaf_count, hdr.leaf_len); }
library/tilecodec/src/main/rust/src/mamaps/write.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/write.rs b/library/tilecodec/src/main/rust/src/mamaps/write.rsindex 1ac36f145b..d642b53a2c 100644--- a/library/tilecodec/src/main/rust/src/mamaps/write.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/write.rs@@ -63,4 +63,3 @@ pub use codec::{compress_body, compress_body_with, hash64}; pub use codec::{compress_body_zstd, compress_body_zstd_level}; pub use options::Options; pub use writer::{content_build_id, StreamWriter};-pub(crate) use writer::Pending;
library/tilecodec/src/main/rust/src/mamaps/write/options.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/write/options.rs b/library/tilecodec/src/main/rust/src/mamaps/write/options.rsindex 49e9be4f6a..ce2f7d01d9 100644--- a/library/tilecodec/src/main/rust/src/mamaps/write/options.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/write/options.rs@@ -2,7 +2,6 @@ use std::path::PathBuf; pub const DEFAULT_LEAF_CAPACITY: u32 = 4096; /// Raw DEFLATE over everything but the body header.- /// What a build declares about itself before the first tile. pub struct Options { pub min_zoom: u8,
library/tilecodec/src/main/rust/src/mamaps/write/spill.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/write/spill.rs b/library/tilecodec/src/main/rust/src/mamaps/write/spill.rsindex 19e2efc081..cb82b3b110 100644--- a/library/tilecodec/src/main/rust/src/mamaps/write/spill.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/write/spill.rs@@ -118,7 +118,7 @@ impl Spill { } /// Append a body the caller hands over whole, through the background writer (started on- /// first use). Same offset, same bytes as [`Self::append`]; the body is written later, in+ /// first use). Same offset, same bytes as the buffered append path; the body is written later, in /// order, and kept in memory until it is. pub(crate) fn append_shared(&mut self, body: std::sync::Arc<Vec<u8>>) -> Result<()> { if self.bg.is_none() {@@ -256,6 +256,9 @@ impl Spill { Ok(()) } + // Buffered append path: exercised by the spill tests and mixed-mode compares;+ // production writers go through `append_shared`, so this is test-only in the lib build.+ #[cfg(test)] pub(crate) fn append(&mut self, bytes: &[u8]) -> Result<()> { if self.bg.is_some() { return self.append_shared(std::sync::Arc::new(bytes.to_vec()));@@ -280,7 +283,7 @@ impl Spill { /// The compare that makes a content-dedup hit a fact rather than a probability. Answered out of /// the buffer when the body is still in it, which costs nothing at all. pub(crate) fn matches_at(&mut self, offset: u64, candidate: &[u8]) -> Result<bool> {- let start = offset as u64;+ let start = offset; let end = start + candidate.len() as u64; debug_assert!(end <= self.len(), "a dedup candidate past the end of the data section"); self.confirms += 1;
library/tilecodec/src/main/rust/src/mamaps/write/writer.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/write/writer.rs b/library/tilecodec/src/main/rust/src/mamaps/write/writer.rsindex eea264e3ec..5cdec5d242 100644--- a/library/tilecodec/src/main/rust/src/mamaps/write/writer.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/write/writer.rs@@ -484,8 +484,6 @@ impl StreamWriter { Ok(out) } - /// Chop the entries into leaves- /// Chop the entries into leaves of at most `capacity`, rebasing each leaf's ids and offsets. /// /// `None` when some leaf's tile-id span will not fit the `u32` a [`LeafEntry::tile_id_lo`]
library/tilecodec/src/main/rust/src/mvt/tests.rs
diff --git a/library/tilecodec/src/main/rust/src/mvt/tests.rs b/library/tilecodec/src/main/rust/src/mvt/tests.rsindex f381c8e419..f245162c07 100644--- a/library/tilecodec/src/main/rust/src/mvt/tests.rs+++ b/library/tilecodec/src/main/rust/src/mvt/tests.rs@@ -83,7 +83,7 @@ fn a_tile_round_trips_through_encode_and_decode() { #[test] fn every_value_kind_round_trips() {- let vals = vec![+ let vals = [ Value::String("s".into()), Value::Float(1.5), Value::Double(-2.25),
library/tilecodec/src/main/rust/src/pmtiles.rs
diff --git a/library/tilecodec/src/main/rust/src/pmtiles.rs b/library/tilecodec/src/main/rust/src/pmtiles.rsindex ddf7322899..a951aac942 100644--- a/library/tilecodec/src/main/rust/src/pmtiles.rs+++ b/library/tilecodec/src/main/rust/src/pmtiles.rs@@ -50,7 +50,6 @@ pub use types::{ COMPRESSION_GZIP, COMPRESSION_NONE, Entry, Header, HEADER_LEN, MAGIC, SPEC_VERSION, TILE_TYPE_MVT, };-pub(crate) use types::MAX_ROOT_BYTES; pub use hilbert::{tile_id, tile_zxy, zoom_base}; pub use directory::{parse_directory, serialize_directory}; pub use read::Archive;
library/tilecodec/src/main/rust/src/pmtiles/tests.rs
diff --git a/library/tilecodec/src/main/rust/src/pmtiles/tests.rs b/library/tilecodec/src/main/rust/src/pmtiles/tests.rsindex cac5886f4a..81a59f007f 100644--- a/library/tilecodec/src/main/rust/src/pmtiles/tests.rs+++ b/library/tilecodec/src/main/rust/src/pmtiles/tests.rs@@ -270,7 +270,7 @@ fn a_large_archive_spills_into_leaf_directories() { let a = Archive::parse(&bytes).unwrap(); assert!(a.header.leaf_length > 0, "must have spilled into leaves"); assert!(- a.header.root_length as usize <= MAX_ROOT_BYTES,+ a.header.root_length as usize <= super::types::MAX_ROOT_BYTES, "root must stay within one request" ); // Spot-check across leaf boundaries.
library/tilecodec/src/main/rust/tests/leaf_compression.rs
diff --git a/library/tilecodec/src/main/rust/tests/leaf_compression.rs b/library/tilecodec/src/main/rust/tests/leaf_compression.rsindex 85fe6c2641..dc722f88d8 100644--- a/library/tilecodec/src/main/rust/tests/leaf_compression.rs+++ b/library/tilecodec/src/main/rust/tests/leaf_compression.rs@@ -14,13 +14,16 @@ use tilecodec::mamaps::body::{ }; use tilecodec::mamaps::dict; use tilecodec::mamaps::header::{Header, FORMAT_VERSION, FORMAT_VERSION_V9, HEADER_LEN};-use tilecodec::mamaps::index::{self, LEAF_ENTRY_LEN, ROOT_ENTRY_LEN, RootEntry};+use tilecodec::mamaps::index::{self, LEAF_ENTRY_LEN, ROOT_ENTRY_LEN}; use tilecodec::mamaps::read::{self, MamapsArchive}; use tilecodec::mamaps::write::{Options, StreamWriter}; use tilecodec::pmtiles::tile_id; use tilecodec::proto::Result; use tilecodec::stream::{RangeReader, OPEN_PREFIX_BYTES}; +type Requests = Rc<RefCell<Vec<(u64, u32)>>>;+type CountingArchive = MamapsArchive<Counting>;+ /// A [`RangeReader`] over bytes in memory that logs every range asked for, so a test can assert /// on the **number of round trips** as well as on the bytes. ///@@ -87,7 +90,7 @@ fn archive(tiles: &[(u8, u64, u64, i16)], options: Options) -> Vec<u8> { writer.finish().expect("finish") } -fn open(bytes: Vec<u8>) -> (MamapsArchive<Counting>, Rc<RefCell<Vec<(u64, u32)>>>) {+fn open(bytes: Vec<u8>) -> (CountingArchive, Requests) { let requests = Rc::new(RefCell::new(Vec::new())); let a = MamapsArchive::open(Counting { bytes, requests: Rc::clone(&requests) }) .expect("open");@@ -147,7 +150,7 @@ fn compressed_leaves_round_trip_and_keep_the_prefix_budget() { } assert!(header.leaf_len < raw_total, "the stored section is smaller than the raw leaves"); // And the whole archive reads back tile-for-tile through the range-reader path.- let (mut a, requests) = open(bytes);+ let (a, requests) = open(bytes); assert_eq!(requests.borrow().len(), 1, "open is still one request"); for (z, x, y, seed) in &tiles { let tile = a.tile(*z, *x as u32, *y as u32).expect("read").expect("present");@@ -176,7 +179,7 @@ fn raw_leaves_stay_byte_identical_and_still_open() { assert_eq!(c1, c2); // Both open and read on the same reader. for bytes in [raw, c1] {- let (mut a, _) = open(bytes);+ let (a, _) = open(bytes); assert_eq!(a.tile(2, 3, 3).expect("read").expect("present"), body_for(15)); } }@@ -187,7 +190,7 @@ fn raw_leaves_stay_byte_identical_and_still_open() { fn a_cold_tile_is_still_two_requests_and_a_warm_tile_one() { let tiles = leafy_tiles(); let options = Options { leaf_entry_capacity: 16, ..Options::default() };- let (mut a, requests) = open(archive(&tiles, options));+ let (a, requests) = open(archive(&tiles, options)); assert!(a.header.leaf_count > 1, "this test needs several leaves"); requests.borrow_mut().clear(); assert!(a.tile(4, 0, 0).expect("read").is_some());