<分区>
我有这个文件 utils.rs
声明了一个 lazy_static
,如下所示:
extern crate geojson;
extern crate geo;
use self::geo::MultiPolygon;
use self::geojson::GeoJson;
use self::geojson::conversion::TryInto;
lazy_static! {
pub static ref LAND_POLYGONS: MultiPolygon<f64> = {
let input_string = include_str!("resources/land.geojson");
let mut polygons: Vec<Polygon<f64>> = vec![];
// ...
// add some polygons here
// ...
MultiPolygon(polygons)
};
}
然后在 main.rs
中我尝试使用 LAND_POLYGONS
如下:
#[macro_use]
extern crate lazy_static;
extern crate geo;
use self::geo::MultiPolygon;
use utils::LAND_POLYGONS;
fn main() -> Result<(), Box<Error>> {
lazy_static::initialize(&LAND_POLYGONS);
println!("{:?}", LAND_POLYGONS);
Ok(())
}
这会产生以下编译器错误:
error[E0277]: `utils::LAND_POLYGONS` doesn't implement `std::fmt::Debug`
--> src/main.rs:30:22
|
30 | println!("{:?}", LAND_POLYGONS);
| ^^^^^^^^^^^^^ `utils::LAND_POLYGONS` cannot be formatted using `:?`; add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `utils::LAND_POLYGONS`
= note: required by `std::fmt::Debug::fmt`
LAND_POLYGONS
似乎是作为其自身类型的实例加载的。
如何赋予 LAND_POLYGONS
正确的类型,改为 geo::MultiPolygon
?作为旁注,MultiPolygon
确实确实实现了 Debug
。
lazy_static
文档和示例使它看起来已经是这种情况,无需任何特殊操作。
注意:将以上所有内容放入一个 main.rs
文件时,结果是相同的。