Struct imf::IMF

source ·
pub struct IMF {
    pub version: u8,
    pub colors: BTreeMap<i32, (u8, u8, u8)>,
    pub width: usize,
    pub height: usize,
    pub map: Vec<i32>,
}
Expand description

Stores the version, colors, width, height and content of an Integer Media File.

Fields§

§version: u8§colors: BTreeMap<i32, (u8, u8, u8)>§width: usize§height: usize§map: Vec<i32>

Implementations§

source§

impl IMF

source

pub fn default() -> IMF

Returns an IMF filled with default values.

source

pub fn new(path: &str) -> Result<IMF, String>

Creates new IMF from file located at filepath. If you want to create a new one from existing variables, declare it like this:

use imf::IMF;

//assuming that all variables already exist
let imf = IMF {
    version,
    colors,
    width,
    height,
    map
};
source

pub fn get_xy(&self, x: usize, y: usize) -> Option<i32>

Returns number found at coordinates within IMF. See IMF::set_xy

§Arguments
  • x - The X coordinate
  • y - The Y coordinate
§Example
 use imf::IMF;
 //example.imf:
 //1,0,1,5,
 //4,7,3,3,
 //9,2,5,6,
 //0,5,8,2

 let mut imf = IMF::new("example.imf").unwrap();
 let n = imf.get_xy(1,1).unwrap();

 // n == 7
source

pub fn set_xy(&mut self, x: usize, y: usize, i: i32) -> bool

Sets number at coordinates within IMF to the number specified. See IMF::get_xy

§Arguments
  • x - The X coordinate
  • y - The Y coordinate
  • i - What the number will be set to
§Example
 use imf::IMF;

 let mut imf = IMF::new("example.imf").unwrap();
 imf.set_xy(2,2,5);

 // imf.get_xy(2,2) == 5
source

pub fn xy2i(&self, x: usize, y: usize) -> usize

Converts XY coordinates to an index. This does not check to see if anything exists at that index. See IMF::i2xy

§Example
use imf::IMF;
//example.imf:
//1,0,1,5,
//4,7,3,3,
//9,2,5,6,
//0,5,8,2

let imf = IMF::new("example.imf").unwrap();
let n = imf.xy2i(2,2);

// n == 10
source

pub fn i2xy(&self, i: usize) -> Option<(usize, usize)>

Converts index to XY coordinates. See IMF::xy2i

§Example
use imf::IMF;
//example.imf:
//1,0,1,5,
//4,7,3,3,
//9,2,5,6,
//0,5,8,2

let imf = IMF::new("example.imf").unwrap();
let n = imf.xy2i(2,2);
let m = imf.i2xy(10);

// n == m
source

pub fn write(&self, path: &str) -> Result<(), String>

Writes IMF to given filepath in .imf form

Trait Implementations§

source§

impl Clone for IMF

source§

fn clone(&self) -> IMF

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for IMF

§

impl RefUnwindSafe for IMF

§

impl Send for IMF

§

impl Sync for IMF

§

impl Unpin for IMF

§

impl UnwindSafe for IMF

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.