Modinfo

Struct Modinfo 

Source
pub struct Modinfo { /* private fields */ }
Expand description

The main struct for the library

§Fields

  • name - the name of the modlet
  • display_name - the display name of the modlet (v2 only)
  • version - the version of the modlet
  • description - the description of the modlet
  • author - the author of the modlet
  • website - 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

Source

pub fn new() -> Self

Create a new Modinfo instance with default values

Source

pub fn write(&self, file: Option<&Path>) -> Result<(), ModinfoError>

Write the Modinfo to a file uses modinfo_version to determine which format to use

Source

pub fn get_value_for<F>(&self, field: F) -> Option<&Cow<'_, str>>
where F: AsRef<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")));
Source

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")));
Source

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));
Source

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));
Source

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);
Source

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);
Source

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"));
Source

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"));
Source

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));
Source

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));
Source

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));
Source

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());
Source

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());

Trait Implementations§

Source§

impl Clone for Modinfo

Source§

fn clone(&self) -> Modinfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Modinfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Modinfo

Source§

fn default() -> Modinfo

Returns the “default value” for a type. Read more
Source§

impl FromStr for Modinfo

Source§

type Err = ModinfoError

The associated error which can be returned from parsing.
Source§

fn from_str(xml: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Modinfo

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Modinfo

Source§

fn cmp(&self, other: &Modinfo) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Modinfo

Source§

fn eq(&self, other: &Modinfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Modinfo

Source§

fn partial_cmp(&self, other: &Modinfo) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToString for Modinfo

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl Eq for Modinfo

Source§

impl StructuralPartialEq for Modinfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.