噩梦级别的类型推导

This commit is contained in:
shenjack 2023-04-09 13:59:36 +08:00
parent fc52c602b8
commit 1b68335f0e
2 changed files with 26 additions and 9 deletions

View File

@ -529,6 +529,16 @@ pub mod ship {
pub child_part: i64, pub child_part: i64,
} }
impl SR1PartDataTrait for Part {
fn to_sr_part_data(&self) -> SR1PartData {
todo!()
}
fn to_raw_part_data(&self) -> Part {
self.clone()
}
}
impl SR1ShipTrait for RawShip { impl SR1ShipTrait for RawShip {
#[inline] #[inline]
fn to_sr_ship(&self, name: Option<String>) -> SR1Ship { fn to_sr_ship(&self, name: Option<String>) -> SR1Ship {
@ -536,26 +546,33 @@ pub mod ship {
for part in &self.parts.parts { for part in &self.parts.parts {
parts.push(part.to_sr_part_data()); parts.push(part.to_sr_part_data());
} }
let disconnected = match self.disconnected { let disconnected = match &self.disconnected {
Some(disconnect) => { Some(disconnect) => {
// let mut disconnect_parts = Vec::new(); // let mut disconnect_parts = Vec::new();
let mut parts = Vec::new();
let mut disconnect_parts = Vec::new();
for disconnected_part in &disconnect.parts { for disconnected_part in &disconnect.parts {
let parts = Vec::new();
for part in disconnected_part.parts.parts { let mut parts_vec = Vec::new();
parts.push(part.to_sr_part_data()); for part in &disconnected_part.parts.parts {
parts_vec.push(part.to_sr_part_data());
} }
parts.push((parts, disconnected_part.connects.connects.clone())); disconnect_parts.push((parts_vec, disconnected_part.connects.connects.clone()));
} }
parts Some(disconnect_parts)
} }
_ => None, _ => None,
}; };
let connections = match &self.connects.connects {
Some(connections) => connections.clone(),
_ => Vec::new(),
};
SR1Ship { SR1Ship {
name: name.unwrap_or("NewShip".to_string()), name: name.unwrap_or("NewShip".to_string()),
description: "".to_string(), description: "".to_string(),
parts, parts,
connections: self.connects.connects.unwrap_or(Vec::new()), connections,
lift_off: i8_to_bool(self.lift_off), lift_off: i8_to_bool(self.lift_off),
touch_ground: i8_to_bool(self.touch_ground), touch_ground: i8_to_bool(self.touch_ground),
disconnected, disconnected,

View File

@ -577,7 +577,7 @@ pub mod sr1 {
disconnected_vec.push(RawDisconnectedPart { disconnected_vec.push(RawDisconnectedPart {
parts: RawParts { parts: raw_parts }, parts: RawParts { parts: raw_parts },
connects: Connections { connects: Connections {
connects: Some(connections.clone()), connects: connections.clone(),
}, },
}); });
} }