pub struct Modinfo { /* private fields */ }Expand description
The main struct for the library
§Fields
name- the name of the modletdisplay_name- the display name of the modlet (v2 only)version- the version of the modletdescription- the description of the modletauthor- the author of the modletwebsite- the website of the modlet (v2 only)
Additionally, version supports an optional compat field which can be used to indicate the game’s version for the compatibility string
§Example
use modinfo::Modinfo;
use std::borrow::Cow;
let mut modinfo = Modinfo::new();
modinfo.set_version("0.1.0".to_owned());
modinfo.set_value_for("name", "SomeMod");
modinfo.set_value_for("display_name", "Some Mod");
modinfo.set_value_for("author", "Some Author");
modinfo.set_value_for("description", "Some Description");
modinfo.set_value_for("website", "https://example.org");
assert_eq!(modinfo.get_value_for("name"), Some(&Cow::from("SomeMod")));
assert_eq!(modinfo.get_value_for("display_name"), Some(&Cow::from("Some Mod")));
assert_eq!(modinfo.get_value_for("author"), Some(&Cow::from("Some Author")));
assert_eq!(modinfo.get_value_for("description"), Some(&Cow::from("Some Description")));
assert_eq!(modinfo.get_value_for("website"), Some(&Cow::from("https://example.org")));
assert_eq!(modinfo.get_version(), &semver::Version::new(0, 1, 0));Implementations§
Source§impl Modinfo
impl Modinfo
Sourcepub fn write(&self, file: Option<&Path>) -> Result<(), ModinfoError>
pub fn write(&self, file: Option<&Path>) -> Result<(), ModinfoError>
Write the Modinfo to a file
uses modinfo_version to determine which format to use
Sourcepub fn get_value_for<F>(&self, field: F) -> Option<&Cow<'_, str>>
pub fn get_value_for<F>(&self, field: F) -> Option<&Cow<'_, str>>
Retrieve the value for a given field.
Note: This is not case-sensitive so you can use get_value_for("Author") or get_value_for("author")
Please note that version is excluded from this function, use get_version instead
use modinfo::Modinfo;
let mut modinfo = Modinfo::default();
modinfo.set_value_for("author", "Joe");
assert_eq!(modinfo.get_value_for("author"), Some(&std::borrow::Cow::from("Joe")));Sourcepub fn set_value_for(&mut self, field: &str, value: &str)
pub fn set_value_for(&mut self, field: &str, value: &str)
Set the value for a given field to value
Note: field is not case-sensitive, so you can use set_value_for("Author", "Joe") or get_value_for("author", "Joe")
use modinfo::Modinfo;
let mut modinfo = Modinfo::default();
modinfo.set_value_for("name", "MyMod");
assert_eq!(modinfo.get_value_for("name"), Some(&std::borrow::Cow::from("MyMod")));Sourcepub fn get_version(&self) -> &Version
pub fn get_version(&self) -> &Version
Retrieve the value for the version field included the ModInfo
Note: This is the version of the modlet, not the version of the ModInfo file format
Please see get_modinfo_version for that.
use modinfo::Modinfo;
let modinfo = Modinfo::default();
assert_eq!(modinfo.get_version(), &semver::Version::new(0, 1, 0));Sourcepub fn set_version(&mut self, version: String)
pub fn set_version(&mut self, version: String)
Sets the version field inside the modinfo.xml file (modlet version)
use modinfo::Modinfo;
let mut modinfo = Modinfo::default();
modinfo.set_version("1.2.3".to_owned());
assert_eq!(modinfo.get_version(), &semver::Version::new(1, 2, 3));Sourcepub fn get_modinfo_version(&self) -> ModinfoVersion
pub fn get_modinfo_version(&self) -> ModinfoVersion
Retrieves the current version of the ModInfo.xml file (V1 or V2)
returns a ModinfoVersion enum:
ModinfoVersion::V1
ModinfoVersion::V2
use modinfo::{Modinfo, ModinfoVersion};
let mut modinfo = Modinfo::default();
assert_eq!(modinfo.get_modinfo_version(), ModinfoVersion::V2);Sourcepub fn set_modinfo_version(&mut self, version: ModinfoVersion)
pub fn set_modinfo_version(&mut self, version: ModinfoVersion)
Sets the version of the ModInfo.xml file itesle (V1 or V2)
Accepts a ModinfoVersion enum:
ModinfoVersion::V1
ModinfoVersion::V2
use modinfo::{Modinfo, ModinfoVersion};
let mut modinfo = Modinfo::default();
modinfo.set_modinfo_version(ModinfoVersion::V1);
assert_eq!(modinfo.get_modinfo_version(), ModinfoVersion::V1);Sourcepub fn get_file_path(&self) -> &PathBuf
pub fn get_file_path(&self) -> &PathBuf
Retrieves the current modinfo.xml file path
use modinfo::Modinfo;
use std::path::PathBuf;
let mut modinfo = Modinfo::default();
modinfo.set_file_path(PathBuf::from("modinfo.xml"));
assert_eq!(modinfo.get_file_path(), &PathBuf::from("modinfo.xml"));Sourcepub fn set_file_path(&mut self, path: PathBuf)
pub fn set_file_path(&mut self, path: PathBuf)
Sets the modinfo.xml file path
This is normally set automatically when a file is parsed, but can be set manually such as when creating a new modinfo.xml file.
use modinfo::Modinfo;
use std::path::PathBuf;
let mut modinfo = Modinfo::default();
modinfo.set_file_path(PathBuf::from("modinfo.xml"));
assert_eq!(modinfo.get_file_path(), &PathBuf::from("modinfo.xml"));Sourcepub fn bump_version_major(&mut self)
pub fn bump_version_major(&mut self)
Increases the Major version number by 1, sets Minor and Patch to 0, and removes any pre or build data.
use modinfo::Modinfo;
let mut modinfo = Modinfo::default();
modinfo.set_version("1.2.3-foo+bar".to_owned());
modinfo.bump_version_major();
assert_eq!(modinfo.get_version(), &semver::Version::new(2, 0, 0));Sourcepub fn bump_version_minor(&mut self)
pub fn bump_version_minor(&mut self)
Increases the Minor version number by 1, sets Patch to 0, and removes any pre or build data.
use modinfo::Modinfo;
let mut modinfo = Modinfo::default();
modinfo.set_version("1.2.3-foo+bar".to_owned());
modinfo.bump_version_minor();
assert_eq!(modinfo.get_version(), &semver::Version::new(1, 3, 0));Sourcepub fn bump_version_patch(&mut self)
pub fn bump_version_patch(&mut self)
Increases the Patch version number by 1, and removes any pre or build data.
use modinfo::Modinfo;
let mut modinfo = Modinfo::default();
modinfo.set_version("1.2.3-foo+bar".to_owned());
modinfo.bump_version_patch();
assert_eq!(modinfo.get_version(), &semver::Version::new(1, 2, 4));Sourcepub fn add_version_pre(&mut self, pre: &str)
pub fn add_version_pre(&mut self, pre: &str)
Adds a pre-release version to the version field
use modinfo::Modinfo;
let mut modinfo = Modinfo::default();
modinfo.set_version("1.2.3".to_owned());
modinfo.add_version_pre("foo");
assert_eq!(modinfo.get_version(), &semver::Version::parse("1.2.3-foo").unwrap());Sourcepub fn add_version_build(&mut self, build: &str)
pub fn add_version_build(&mut self, build: &str)
Adds build data to the version field
use modinfo::Modinfo;
let mut modinfo = Modinfo::default();
modinfo.set_version("1.2.3".to_owned());
modinfo.add_version_build("bar");
assert_eq!(modinfo.get_version(), &semver::Version::parse("1.2.3+bar").unwrap());