# base/version (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/base/version/

Version. (major.minor.patch, major.minor.patch-branch if there is a branch, the original base/version.js)
- The fields are left open, and the original's accessors like get_major / set_major and getVersionString are kept under the same names.
- The branch is a string, so it is not Copy. create has no branch like the original default arguments, and create_with_branch takes a branch.

## Version (struct) (Clone, Debug, PartialEq, Eq)

Version. (major, minor and patch numbers and branch name)

Example: Build a version string and add a branch

```rust
use vanilla::Version;

let mut version = Version::create(0, 4, 0);
assert_eq!(version.to_string(), "0.4.0");
version.set_branch("experimental");
assert_eq!(version.get_version_string(), "0.4.0-experimental");
version.patch += 1;
assert_eq!(version, Version::create_with_branch(0, 4, 1, "experimental"));
```

- `pub major: u32` (field, since 0.3.2): Major version number.
  - returns u32
- `pub minor: u32` (field, since 0.3.2): Minor version number.
  - returns u32
- `pub patch: u32` (field, since 0.3.2): Patch version number.
  - returns u32
- `pub branch: String` (field, since 0.4.0): Branch name. (no branch if empty)
  - returns String
- `pub const fn create(major: u32, minor: u32, patch: u32) -> Version` (static, since 0.3.2): Constructor. (no branch)
  - `major` u32: Major version number.
  - `minor` u32: Minor version number.
  - `patch` u32: Patch version number.
  - returns Version: A version with no branch. (a const fn, so it can be kept as a constant)

  Example: The game version as a constant

  ```rust
  use vanilla::Version;
  
  const GAME_VERSION: Version = Version::create(1, 2, 3);
  assert_eq!(GAME_VERSION.to_string(), "1.2.3");
  ```

- `pub fn create_with_branch(major: u32, minor: u32, patch: u32, branch: &str) -> Version` (static, since 0.4.0): Creates with a branch. (no branch if empty)
  - `major` u32: Major version number.
  - `minor` u32: Minor version number.
  - `patch` u32: Patch version number.
  - `branch` &str: Branch name. (no branch if empty)
  - returns Version: A version with that branch attached.
- `pub fn set_major(&mut self, major: u32)` (method, since 0.4.0): Sets and returns the major version.
  - `major` u32: New major version number.
- `pub fn get_major(&self) -> u32` (method, since 0.4.0): Returns the major version.
  - returns u32: Major version number.
- `pub fn set_minor(&mut self, minor: u32)` (method, since 0.4.0): Sets and returns the minor version.
  - `minor` u32: New minor version number.
- `pub fn get_minor(&self) -> u32` (method, since 0.4.0): Returns the minor version.
  - returns u32: Minor version number.
- `pub fn set_patch(&mut self, patch: u32)` (method, since 0.4.0): Sets and returns the patch version.
  - `patch` u32: New patch version number.
- `pub fn get_patch(&self) -> u32` (method, since 0.4.0): Returns the patch version.
  - returns u32: Patch version number.
- `pub fn set_branch(&mut self, branch: &str)` (method, since 0.4.0): Sets and returns the branch. (no branch if empty)
  - `branch` &str: New branch name. (no branch if empty)
- `pub fn get_branch(&self) -> &str` (method, since 0.4.0): Returns the branch.
  - returns &str: Branch name. (empty string if none)
- `pub fn get_version_string(&self) -> String` (method, since 0.4.0): Version string. (the original getVersionString, same as to_string)
  - returns String: Version string, same as to_string.
- `pub fn to_string(&self) -> String` (method, since 0.3.2): "major.minor.patch" string. ("major.minor.patch-branch" if there is a branch)
  - returns String: Version string. ("0.3.2"; a branch is appended after a hyphen, like "0.4.0-experimental")
