diff --git a/mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock b/mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock index ac412da..35285d6 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock +++ b/mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock @@ -67,9 +67,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crossbeam" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" +checksum = "6eb9105919ca8e40d437fc9cbb8f1975d916f1bd28afe795a48aae32a2cc8920" dependencies = [ "cfg-if", "crossbeam-channel", @@ -81,9 +81,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c3242926edf34aec4ac3a77108ad4854bffaa2e4ddc1824124ce59231302d5" +checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2" dependencies = [ "cfg-if", "crossbeam-utils", @@ -102,21 +102,20 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.16" +version = "0.9.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2fe95351b870527a5d09bf563ed3c97c0cffb87cf1c78a591bf48bb218d9aa" +checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset", ] [[package]] name = "crossbeam-queue" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9bcf5bdbfdd6030fb4a1c497b5d5fc5921aa2f60d359a17e249c0e6df3de153" +checksum = "adc6598521bb5a83d491e8c1fe51db7296019d2ca3cb93cc6c2a20369a4d78a2" dependencies = [ "cfg-if", "crossbeam-utils", @@ -124,9 +123,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.17" +version = "0.8.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" +checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" dependencies = [ "cfg-if", ] @@ -144,7 +143,7 @@ dependencies = [ [[package]] name = "difficult_rocket_rs" -version = "0.3.0" +version = "0.3.1" dependencies = [ "dict_derive", "fs-err", @@ -381,9 +380,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8" dependencies = [ "unicode-ident", ] @@ -434,7 +433,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.41", + "syn 2.0.42", ] [[package]] @@ -446,7 +445,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.42", ] [[package]] @@ -548,7 +547,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.42", ] [[package]] @@ -604,9 +603,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" dependencies = [ "proc-macro2", "quote", @@ -718,20 +717,20 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "zerocopy" -version = "0.7.31" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.31" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.42", ] diff --git a/mods/dr_game/Difficult_Rocket_rs/src/Cargo.toml b/mods/dr_game/Difficult_Rocket_rs/src/Cargo.toml index 1fbd9a5..58dbe93 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/Cargo.toml +++ b/mods/dr_game/Difficult_Rocket_rs/src/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "difficult_rocket_rs" -version = "0.3.0" +version = "0.3.1" edition = "2021" license-file = '../../LICENSE' authors = ["shenjackyuanjie <3695888@qq.com>"] @@ -14,13 +14,10 @@ crate-type = ["cdylib"] #[profile.dev.package.rapier2d-f64] #opt-level = 2 -[profile.dev] -opt-level = 0 - [profile.release] lto = "fat" -# Abort panic info to rapidly terminate program instead of unwinding call stacks. -# To check panic info, compile the program in dev mode. +# 舍弃恐慌信息以快速终止程序,而非展开调用栈。 +# 请以开发模式编译程序以检查恐慌信息。 panic = "abort" opt-level = 2 @@ -28,9 +25,7 @@ opt-level = 2 fs-err = "2.11.0" quick-xml = { version = "0.31.0", features = ["serialize"] } serde = { version = "1.0", features = ["derive"] } - nalgebra = "0.32.3" rapier2d-f64 = { version = "0.17.2", features = ["simd-stable"] } - pyo3 = { version = "0.20.0", features = ["extension-module", "macros"] } dict_derive = "0.5" diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/rustfmt.toml b/mods/dr_game/Difficult_Rocket_rs/src/rustfmt.toml similarity index 100% rename from mods/dr_game/Difficult_Rocket_rs/src/src/rustfmt.toml rename to mods/dr_game/Difficult_Rocket_rs/src/rustfmt.toml diff --git a/mods/dr_game/Difficult_Rocket_rs/src/setup.py b/mods/dr_game/Difficult_Rocket_rs/src/setup.py index daed2e1..a1f97cc 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/setup.py +++ b/mods/dr_game/Difficult_Rocket_rs/src/setup.py @@ -12,7 +12,7 @@ package_path = "Difficult_Rocket_rs" setup( name="Difficult_Rocket_rs", - version="0.3.0", + version="0.3.1", author="shenjackyuanjie", author_email="3695888@qq.com", rust_extensions=[ diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/data_type.rs deleted file mode 100644 index 3756eb5..0000000 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type.rs +++ /dev/null @@ -1,13 +0,0 @@ -/* - * ------------------------------- - * Difficult Rocket - * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com - * All rights reserved - * ------------------------------- - */ - -pub mod dr; -pub mod math; -pub mod sr1; - -pub type IdType = i64; diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics.rs new file mode 100644 index 0000000..a144ea4 --- /dev/null +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics.rs @@ -0,0 +1,3 @@ +pub mod math; +pub mod rigid; +pub mod simulation; diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/math.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics/math.rs similarity index 98% rename from mods/dr_game/Difficult_Rocket_rs/src/src/data_type/math.rs rename to mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics/math.rs index dadab5a..9bd6565 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/math.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics/math.rs @@ -1,6 +1,6 @@ pub const POINT_D: f64 = 1.0; -pub trait Rotatable { +pub trait Rotate { // 懒了,直接实现一个协议得了 fn rotate(&self, angle: f64) -> Self; fn rotate_radius(&self, radius: f64) -> Self; @@ -44,7 +44,7 @@ impl Point2D { } } -impl Rotatable for Point2D { +impl Rotate for Point2D { fn rotate_radius(&self, radius: f64) -> Self { let sin = radius.sin(); let cos = radius.cos(); @@ -85,13 +85,14 @@ pub struct OneTimeLine { // pub b: f64, // y = kx + b // kx + b - y = 0 - pub start: Point2D, + // start point - pub end: Point2D, + pub start: Point2D, // end point + pub end: Point2D, } -impl Rotatable for OneTimeLine { +impl Rotate for OneTimeLine { fn rotate(&self, angle: f64) -> Self { self.rotate_radius(angle.to_radians()) } diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/dr.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics/rigid.rs similarity index 100% rename from mods/dr_game/Difficult_Rocket_rs/src/src/data_type/dr.rs rename to mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics/rigid.rs diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/simulator.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics/simulation.rs similarity index 100% rename from mods/dr_game/Difficult_Rocket_rs/src/src/simulator.rs rename to mods/dr_game/Difficult_Rocket_rs/src/src/dr_physics/simulation.rs diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs index 7b1aae1..834a642 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs @@ -6,18 +6,18 @@ * ------------------------------- */ -mod data_type; -mod plugin_loader; +mod dr_physics; mod python; -mod simulator; -mod sr1_data; +mod sr1_parse; mod xml_reader; use pyo3::prelude::*; +pub type IdType = i64; + #[pyfunction] fn get_version_str() -> String { - "0.3.0".to_string() + "0.3.1".to_string() } #[pyfunction] @@ -31,8 +31,8 @@ fn test_call(py_obj: &PyAny) -> PyResult { fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(get_version_str, m)?)?; m.add_function(wrap_pyfunction!(test_call, m)?)?; - m.add_function(wrap_pyfunction!(sr1_data::part_list::read_part_list_py, m)?)?; - m.add_function(wrap_pyfunction!(sr1_data::ship::py_raw_ship_from_file, m)?)?; + m.add_function(wrap_pyfunction!(sr1_parse::part_list::read_part_list_py, m)?)?; + m.add_function(wrap_pyfunction!(sr1_parse::ship::py_raw_ship_from_file, m)?)?; m.add_function(wrap_pyfunction!(python::data::load_and_save_test, m)?)?; m.add_class::()?; m.add_class::()?; diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/plugin_loader.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/plugin_loader.rs deleted file mode 100644 index 79e578f..0000000 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/plugin_loader.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * ------------------------------- - * Difficult Rocket - * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com - * All rights reserved - * ------------------------------- - */ - -// TODO libloading - -/// https://docs.rs/libloading/latest/libloading/ -/// 插件加载 -/// - -pub struct ModInfo { - pub name: String, - pub version: String, -} - -pub trait ModInfoTrait { - fn info() -> ModInfo; -} diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/python/data.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/python/data.rs index 41807e2..88fad42 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/python/data.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python/data.rs @@ -3,13 +3,13 @@ use std::collections::HashMap; use pyo3::exceptions::PyValueError; use pyo3::prelude::*; -use crate::data_type::math::{Point2D, Rotatable}; -use crate::data_type::sr1::SaveStatus; -use crate::data_type::sr1::{get_max_box, SR1PartData, SR1PartListTrait}; -use crate::data_type::sr1::{SR1PartList, SR1PartType, SR1Ship}; -use crate::data_type::IdType; -use crate::sr1_data::part_list::RawPartList; -use crate::sr1_data::ship::RawShip; +use crate::dr_physics::math::{Point2D, Rotate}; +use crate::sr1_parse::part_list::RawPartList; +use crate::sr1_parse::ship::RawShip; +use crate::sr1_parse::SaveStatus; +use crate::sr1_parse::{get_max_box, SR1PartData, SR1PartListTrait}; +use crate::sr1_parse::{SR1PartList, SR1PartType, SR1Ship}; +use crate::IdType; // use serde_xml_rs::to_string; use quick_xml::se::to_string; diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/python/editor.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/python/editor.rs index 7b31069..7cd9cbc 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/python/editor.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python/editor.rs @@ -10,7 +10,7 @@ use nalgebra::{Matrix2, Vector2}; use pyo3::prelude::*; use rapier2d_f64::math::Real; -use crate::data_type::IdType; +use crate::IdType; /// Id 位置 碰撞体 pub type BoundedShape = (IdType, Vector2, EditorShapeEnum); diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/sr1.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse.rs similarity index 98% rename from mods/dr_game/Difficult_Rocket_rs/src/src/data_type/sr1.rs rename to mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse.rs index 539ff83..45f4c7b 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/sr1.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse.rs @@ -1,22 +1,26 @@ +mod data_structure; + +pub use self::data_structure::*; + use std::cell::{Cell, RefCell}; use std::collections::HashMap; -use std::fs; use std::io::Cursor; use std::ops::Deref; -use super::math::{Edge, Shape}; -use crate::sr1_data::part_list::Damage as RawDamage; -use crate::sr1_data::part_list::{AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank}; -use crate::sr1_data::part_list::{RawPartList, RawPartType, SR1PartTypeEnum}; -use crate::sr1_data::ship::{ +use crate::dr_physics::math::{Edge, Shape}; +use crate::sr1_parse::part_list::Damage as RawDamage; +use crate::sr1_parse::part_list::{AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank}; +use crate::sr1_parse::part_list::{RawPartList, RawPartType, SR1PartTypeEnum}; +use crate::sr1_parse::ship::{ Activate as RawActivate, Connection, Connections, DisconnectedPart as RawDisconnectedPart, DisconnectedParts as RawDisconnectedParts, Engine as RawEngine, Part as RawPartData, Parts as RawParts, Pod as RawPod, RawShip, Staging as RawStaging, Step as RawStep, Tank as RawTank, }; -use crate::data_type::math::{Point2D, Rotatable}; -use crate::data_type::IdType; +use crate::dr_physics::math::{Point2D, Rotate}; +use crate::IdType; +use fs_err as fs; use quick_xml::events::{BytesEnd, BytesStart, Event}; use quick_xml::writer::Writer; @@ -45,11 +49,11 @@ pub enum SR1PartTypeAttr { consumption: f64, size: f64, turn: f64, - fuel_type: i32, /// 0 -> 普通燃料 /// 1 -> Rcs /// 2 -> 电量 /// 3 -> 固推 + fuel_type: i32, throttle_exponential: bool, }, Rcs { @@ -161,7 +165,6 @@ pub struct SR1PartList { } impl SR1PartList { - #[inline] pub fn new(name: String, types: Vec) -> SR1PartList { SR1PartList { types, @@ -170,7 +173,6 @@ impl SR1PartList { } } - #[inline] pub fn from_file(file_name: String) -> Option { if let Some(raw_list) = RawPartList::from_file(file_name) { let sr_list = raw_list.to_sr_part_list(None); @@ -191,7 +193,6 @@ impl SR1PartList { self.cache.borrow().clone().unwrap() } - #[inline] pub fn get_part_type(&self, type_name: &String) -> Option { let cache = self.get_cache(); cache.get(type_name).cloned() @@ -373,12 +374,10 @@ impl SR1PartTypeData for SR1PartType { } impl SR1PartDataTrait for SR1PartData { - #[inline] fn to_sr_part_data(&self) -> SR1PartData { self.clone() } - #[inline] fn to_raw_part_data(&self) -> RawPartData { let (tank, engine) = if let Some(fuel) = &self.attr.fuel { match self.part_type { @@ -600,7 +599,6 @@ impl SR1PartDataAttr { Some(pod.throttle), Some(pod.stages.current_stage), Some({ - // The mother-fucking nests come out again! let mut steps = Vec::new(); match &pod.stages.steps { Some(step_vec) => { @@ -697,7 +695,6 @@ impl SR1Ship { part.part_type = SR1PartTypeEnum::strut; } } - // Why are you fucking nesting such this fucking loops?! for disconnects in self.disconnected.iter_mut() { for (parts, _) in disconnects.iter_mut() { for part in parts.iter_mut() { diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse/data_structure.rs similarity index 100% rename from mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs rename to mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse/data_structure.rs diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data/part_list.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse/data_structure/part_list.rs similarity index 98% rename from mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data/part_list.rs rename to mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse/data_structure/part_list.rs index 750ab22..69247c6 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data/part_list.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse/data_structure/part_list.rs @@ -1,10 +1,10 @@ -use crate::data_type::sr1::{SR1PartList, SR1PartType, SR1PartTypeAttr}; -use crate::data_type::sr1::{SR1PartListTrait, SR1PartTypeData}; +use crate::sr1_parse::{SR1PartList, SR1PartType, SR1PartTypeAttr}; +use crate::sr1_parse::{SR1PartListTrait, SR1PartTypeData}; use fs_err as fs; use pyo3::prelude::*; -use serde::{Deserialize, Serialize}; use quick_xml::de::from_str; +use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct RawPartList { @@ -138,8 +138,8 @@ pub struct Damage { } impl Damage { - pub fn take_damage(&self) -> crate::data_type::sr1::Damage { - crate::data_type::sr1::Damage { + pub fn take_damage(&self) -> crate::sr1_parse::Damage { + crate::sr1_parse::Damage { disconnect: self.disconnect, explode: self.explode, explosion_power: self.explosion_power.unwrap_or(100_f64), diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data/ship.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse/data_structure/ship.rs similarity index 98% rename from mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data/ship.rs rename to mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse/data_structure/ship.rs index 0cde0fb..3e70c94 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data/ship.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse/data_structure/ship.rs @@ -6,9 +6,9 @@ use quick_xml::se::to_string; // use quick_xml::Error as XmlError; use serde::{Deserialize, Serialize}; -use crate::data_type::sr1::{SR1PartData, SR1PartDataAttr, SR1Ship}; -use crate::data_type::sr1::{SR1PartDataTrait, SR1ShipTrait}; -use crate::data_type::IdType; +use crate::sr1_parse::{SR1PartData, SR1PartDataAttr, SR1Ship}; +use crate::sr1_parse::{SR1PartDataTrait, SR1ShipTrait}; +use crate::IdType; /// https://docs.rs/quick-xml/latest/quick_xml/de/index.html#basics /// using quick xml diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/xml_reader.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/xml_reader.rs index af3a63b..d03b5a2 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/xml_reader.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/xml_reader.rs @@ -2,14 +2,14 @@ use std::io; use fs_err as fs; -// Input the directory of the xml file. -// If file does not exsit or not the XML file, return errors or return file handle. -// I think this fuction can be improved as its implementations are not as good as what I expected. -pub fn read_xml(dir: &str) -> io::Result { - if dir.split_inclusive('.').collect::>()[1] != "xml" { +// 输入XML文件的路径。 +// 若文件不存在或非XML文件,则返回错误,否则返回文件句柄。 +// 我认为该函数仍可改进,因为它的实现并未达到我所预期的那样。 +pub fn read_xml(path: &str) -> io::Result { + if path.split_inclusive('.').collect::>()[1] != "xml" { Err(io::Error::new(io::ErrorKind::Other, "This file is not an XML file!")) } else { - fs::File::open(dir) + fs::File::open(path) } }