Function shapefile::record::convert_shapes_to_vec_of[][src]

pub fn convert_shapes_to_vec_of<S>(shapes: Vec<Shape>) -> Result<Vec<S>, Error> where
    S: TryFrom<Shape>,
    Error: From<<S as TryFrom<Shape>>::Error>, 

Function that can converts a Vec<Shape> to a vector of any real struct (ie Polyline, Multipatch, etc) if all the Shapes in the Vec are of the correct corresponding variant.

Examples

use shapefile::{Polyline, Multipoint, Point, Shape};
use shapefile::convert_shapes_to_vec_of;

// Build a Vec<Shape> with only polylines in it
let points = vec![Point::default(), Point::default()];
let shapes = vec![
    Shape::from(Polyline::new(points.clone())),
    Shape::from(Polyline::new(points)),
];

// try a conversion to the wrong type
assert_eq!(convert_shapes_to_vec_of::<Multipoint>(shapes).is_ok(), false);
use shapefile::{convert_shapes_to_vec_of, MultipointZ};
let shapes = shapefile::read_shapes("tests/data/multipointz.shp")?;
let multipoints = convert_shapes_to_vec_of::<MultipointZ>(shapes);
assert_eq!(multipoints.is_ok(), true);