Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #102

Merged
merged 7 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changelog

All notable changes to this project will be documented in this file.

## [0.4.2] - 2023-07-31

### Chore

- Update Cargo lock

## [0.2.1] - 2023-01-25

### Bug Fixes

- Pprof can not build on windows (#36)

<!-- generated by git-cliff -->
56 changes: 28 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
name = "tzf-rs"
readme = "README.md"
repository = "https://github.com/ringsaturn/tzf-rs"
version = "0.4.3"
version = "0.4.4"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
8 changes: 4 additions & 4 deletions benches/finders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use rand::seq::SliceRandom;
use tzf_rs::{DefaultFinder, Finder};

lazy_static! {
static ref DEFAULT_FINDER: DefaultFinder = DefaultFinder::new();
static ref FINDER: Finder = Finder::new();
static ref DEFAULT_FINDER: DefaultFinder = DefaultFinder::default();
static ref FINDER: Finder = Finder::default();
}

fn bench_default_finder_random_city(_i: usize) {
Expand All @@ -28,10 +28,10 @@ fn bench_finders(c: &mut Criterion) {

let i = &0;
group.bench_with_input(BenchmarkId::new("Default", i), i, |b, _i| {
b.iter(|| bench_default_finder_random_city(black_box(1)))
b.iter(|| bench_default_finder_random_city(black_box(1)));
});
group.bench_with_input(BenchmarkId::new("Finder", i), i, |b, _i| {
b.iter(|| bench_finder_random_city(black_box(1)))
b.iter(|| bench_finder_random_city(black_box(1)));
});

group.finish();
Expand Down
3 changes: 1 addition & 2 deletions benches/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
#[cfg(test)]
mod benches_default {

use cities_json;
use tzf_rs::DefaultFinder;
extern crate test;
use test::Bencher;
#[bench]
fn bench_default_finder_random_city(b: &mut Bencher) {
let finder: DefaultFinder = DefaultFinder::new();
let finder: DefaultFinder = DefaultFinder::default();

b.iter(|| {
let city = cities_json::get_random_cities();
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ fn main() {
Some(_) => prost_build::Config::new()
.out_dir("src/gen/")
.compile_protos(&["./tzinfo.proto"], &["."])
.unwrap(),
.unwrap_or_default(),
None => println!("no need for pb"),
}

Command::new("cargo")
.args(&["fmt", "--", "src/*.rs"])
.args(["fmt", "--", "src/*.rs"])
.status()
.expect("cargo fmt failed");
}
9 changes: 5 additions & 4 deletions src/bin/tzf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ use tzf_rs::DefaultFinder;
#[command(name = "tzf")]
struct Cli {
/// longitude
#[arg(long)]
#[arg(long, allow_negative_numbers(true), alias("lon"))]
lng: f64,

/// latitude
#[arg(long)]
#[arg(long, allow_negative_numbers(true))]
lat: f64,
}

pub fn main() {
let cli = Cli::parse();
let finder = DefaultFinder::new();
println!("{:?}", finder.get_tz_name(cli.lng, cli.lat));
let finder = DefaultFinder::default();
let tz_name = finder.get_tz_name(cli.lng, cli.lat);
println!("{tz_name:?}");
}
4 changes: 2 additions & 2 deletions src/gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ impl TryFrom<Vec<u8>> for Timezones {
type Error = anyhow::Error;

fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
Ok(Timezones::decode(&value[..])?)
Ok(Self::decode(&value[..])?)
}
}

impl TryFrom<Vec<u8>> for PreindexTimezones {
type Error = anyhow::Error;

fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
Ok(PreindexTimezones::decode(&value[..])?)
Ok(Self::decode(&value[..])?)
}
}
30 changes: 20 additions & 10 deletions src/gen/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub struct Point {
#[prost(float, tag = "2")]
pub lat: f32,
}
/// Define a polygon, mostly based on GeoJSON's Polygon define.
evensolberg marked this conversation as resolved.
Show resolved Hide resolved

/// Define a polygon, mostly based on `GeoJSON`'s Polygon define.
///
/// Excerpt from RFC-9476 section 'Polygon'
///
Expand Down Expand Up @@ -47,6 +48,7 @@ pub struct Polygon {
#[prost(message, repeated, tag = "2")]
pub holes: ::prost::alloc::vec::Vec<Polygon>,
}

/// Timezone is a timezone's all data.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand All @@ -56,6 +58,7 @@ pub struct Timezone {
#[prost(string, tag = "2")]
pub name: ::prost::alloc::string::String,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Timezones {
Expand All @@ -67,6 +70,7 @@ pub struct Timezones {
#[prost(string, tag = "3")]
pub version: ::prost::alloc::string::String,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CompressedPolygon {
Expand All @@ -75,7 +79,8 @@ pub struct CompressedPolygon {
#[prost(message, repeated, tag = "2")]
pub holes: ::prost::alloc::vec::Vec<CompressedPolygon>,
}
/// CompressedTimezonesItem designed for binary file as small as possible.

/// `CompressedTimezonesItem` designed for binary file as small as possible.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CompressedTimezone {
Expand All @@ -84,6 +89,7 @@ pub struct CompressedTimezone {
#[prost(string, tag = "2")]
pub name: ::prost::alloc::string::String,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CompressedTimezones {
Expand All @@ -94,7 +100,8 @@ pub struct CompressedTimezones {
#[prost(string, tag = "3")]
pub version: ::prost::alloc::string::String,
}
/// PreindexTimezone tile item.

/// `PreindexTimezone` tile item.
///
/// The X/Y/Z are OSM style like map tile index values.
#[allow(clippy::derive_partial_eq_without_eq)]
Expand All @@ -109,7 +116,8 @@ pub struct PreindexTimezone {
#[prost(int32, tag = "4")]
pub z: i32,
}
/// PreindexTimezones is all preindex timezone's dumps.

/// `PreindexTimezones` is all preindex timezone's dumps.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PreindexTimezones {
Expand All @@ -124,6 +132,7 @@ pub struct PreindexTimezones {
#[prost(string, tag = "4")]
pub version: ::prost::alloc::string::String,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum CompressMethod {
Expand All @@ -132,17 +141,18 @@ pub enum CompressMethod {
Polyline = 1,
}
impl CompressMethod {
/// String value of the enum field names used in the ProtoBuf definition.
/// String value of the enum field names used in the `ProtoBuf` definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
/// (if the `ProtoBuf` definition does not change) and safe for programmatic use.
pub const fn as_str_name(self) -> &'static str {
match self {
CompressMethod::Unknown => "Unknown",
CompressMethod::Polyline => "Polyline",
Self::Unknown => "Unknown",
Self::Polyline => "Polyline",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.

/// Creates an enum from field names used in the `ProtoBuf` definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"Unknown" => Some(Self::Unknown),
Expand Down
Loading