E0599 依存ライブラリのバージョン不整合に起因する事例
flatgeobufからgeoの型に変換するプログラム
code:main.rs
use flatgeobuf::{FallibleStreamingIterator, FgbReader};
use geozero::ToGeo;
use std::fs::File;
use std::io::BufReader;
fn main() {
let mut filein = BufReader::new(File::open("countries.fgb").unwrap());
let mut fgb = FgbReader::open(&mut filein).unwrap().select_all().unwrap();
while let Some(feature) = fgb.next().unwrap() {
println!("{:?}", feature.to_geo().unwrap());
}
}
問題の依存関係
code:Cargo.toml
name = "playground"
version = "0.1.0"
edition = "2021"
flatgeobuf = "3.25.0"
geo = "0.25.1"
geozero = "0.10.0"
ビルドエラー
errorE0599: the method to_geo exists for reference &FgbFeature, but its trait bounds were not satisfied --> src/main.rs:9:34
|
9 | println!("{:?}", feature.to_geo().unwrap());
| ^^^^^^ method cannot be called on &FgbFeature due to unsatisfied trait bounds
|
::: /home/p4/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flatgeobuf-3.25.0/src/properties_reader.rs:11:1
|
11 | pub struct FgbFeature {
| ---------------------
| |
| doesn't satisfy FgbFeature: ToGeo
| doesn't satisfy FgbFeature: geozero::GeozeroGeometry
|
= note: the following trait bounds were not satisfied:
FgbFeature: geozero::GeozeroGeometry
which is required by FgbFeature: ToGeo
&FgbFeature: geozero::GeozeroGeometry
which is required by &FgbFeature: ToGeo
flatgeobuf 3.25.0 が依存する geozero のバージョンは 0.9.9 だった。
今回作成中のプログラムも同じバージョンの geozero を使うように揃えると、ビルドエラーが解消した。
code:Cargo.toml
geozero = "0.9.9"