Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Default)]
- pub struct Coord {
- pub lon: f64,
- pub lat: f64,
- }
- impl From<(String, String)> for Coord {
- fn from((str_lon, str_lat): (String, String)) -> Self {
- Self {
- lon: if str_lon.is_empty() {
- <f64>::default()
- } else {
- str_lon.parse::<f64>().unwrap()
- },
- lat: if str_lat.is_empty() {
- <f64>::default()
- } else {
- str_lat.parse::<f64>().unwrap()
- },
- }
- }
- }
- impl Into<(String, String)> for Coord {
- fn into(self) -> (String, String) {
- (
- if self.lon == <f64>::default() {
- "".to_string()
- } else {
- self.lon.to_string()
- },
- if self.lat == <f64>::default() {
- "".to_string()
- } else {
- self.lat.to_string()
- },
- )
- }
- }
- fn main() {
- let test = "".to_string();
- assert!(test.is_empty());
- let coord = Coord{lon: 0.0, lat: 0.0};
- let (lat, lon) = coord.into();
- assert_eq!(lat, "");
- assert_eq!(lon, "");
- let coord = Coord::from(("".to_string(),"".to_string()));
- assert_eq!(coord.lon, <f64>::default());
- assert_eq!(coord.lat, <f64>::default());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement