• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-S2 / open-vector-tile / #49

17 Feb 2025 08:39PM UTC coverage: 40.419% (-58.3%) from 98.718%
#49

push

Mr Martian
setup a wasm build for experimentation; main rust didnt have no_std (bug)

18 of 18 new or added lines in 3 files covered. (100.0%)

2956 existing lines in 15 files now uncovered.

2082 of 5151 relevant lines covered (40.42%)

107.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/rust/mapbox/vector_tile.rs
1
use pbf::{ProtoRead, Protobuf};
2

3
use alloc::collections::BTreeMap;
4
use alloc::rc::Rc;
5
use alloc::string::String;
6
use alloc::vec::Vec;
7

8
use core::cell::RefCell;
9

10
use crate::{
11
    base::BaseVectorTile,
12
    mapbox::{write_layer, MapboxVectorLayer},
13
};
14

15
/// The vector tile struct that covers both "open" and "mapbox" specifications
16
#[derive(Debug)]
17
pub struct MapboxVectorTile {
18
    /// the layers in the vector tile
19
    pub layers: BTreeMap<String, MapboxVectorLayer>,
20
    /// the protobuf for the vector tile
21
    pbf: Rc<RefCell<Protobuf>>,
22
}
23
impl MapboxVectorTile {
24
    /// Create a new vector tile
UNCOV
25
    pub fn new(data: Vec<u8>, end: Option<usize>) -> Self {
×
UNCOV
26
        let pbf = Rc::new(RefCell::new(data.into()));
×
UNCOV
27
        let mut vt = MapboxVectorTile { pbf: pbf.clone(), layers: BTreeMap::new() };
×
UNCOV
28

×
UNCOV
29
        let mut tmp_pbf = pbf.borrow_mut();
×
UNCOV
30
        tmp_pbf.read_fields(&mut vt, end);
×
UNCOV
31

×
UNCOV
32
        vt
×
UNCOV
33
    }
×
34

35
    /// Get a layer given the name
UNCOV
36
    pub fn layer(&mut self, name: &str) -> Option<&mut MapboxVectorLayer> {
×
UNCOV
37
        self.layers.get_mut(name)
×
UNCOV
38
    }
×
39
}
40
impl ProtoRead for MapboxVectorTile {
UNCOV
41
    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
×
UNCOV
42
        match tag {
×
UNCOV
43
            1 | 3 => {
×
UNCOV
44
                let mut layer = MapboxVectorLayer::new(self.pbf.clone(), tag == 1);
×
UNCOV
45
                pb.read_message(&mut layer);
×
UNCOV
46
                self.layers.insert(layer.name.clone(), layer);
×
UNCOV
47
            }
×
48
            #[tarpaulin::skip]
49
            _ => panic!("unknown tag: {}", tag),
×
50
        }
UNCOV
51
    }
×
52
}
53

54
/// writer for converting a BaseVectorTile to encoded bytes of the Open Vector Flat Tile format or Mapbox Vector Tile
UNCOV
55
pub fn write_tile(tile: &mut BaseVectorTile, mapbox_support: bool) -> Vec<u8> {
×
UNCOV
56
    let mut pbf = Protobuf::new();
×
57

58
    // first write layers
UNCOV
59
    for layer in tile.layers.values() {
×
UNCOV
60
        pbf.write_bytes_field(
×
UNCOV
61
            if mapbox_support { 3 } else { 1 },
×
UNCOV
62
            &write_layer(layer, mapbox_support),
×
63
        );
64
    }
65

UNCOV
66
    pbf.take()
×
UNCOV
67
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc