[][src]Enum tweep::Position

pub enum Position {
    Column(usize),
    RowColumn(usizeusize),
    File(Stringusizeusize),
    StoryLevel,
}

A position within the content of a Twee story.

By default, a Position is a global StoryLevel. Additional context can be added from there to create a position at File, row, and column level.

Notes

When setting an individual field of a Position, if the current enum variant does not support that field, the value will automatically be promoted to the most general variant that does support that field and default values will be used for any remaining, unset fields. For instance, if set_column is called on a StoryLevel variant, it will be promoted to a Column variant with the given column value. However, if set_file is called on a Column variant, it will be promoted to a File variant, which will contain the newly set filename, the existing column value, and a default row value of 1.

Variants

Column(usize)

A column location, contains the column number

RowColumn(usizeusize)

A row and column location, contains the row number then column number

File(Stringusizeusize)

A file location, contains the file name, row, and column

StoryLevel

Default, global level

Methods

impl Position[src]

pub fn get_column(&self) -> Option<usize>[src]

Gets the column of this Position if one exists.

Examples

use tweep::Position;
let mut pos = Position::default();
assert_eq!(pos.get_column(), None);
pos.set_column(5);
assert_eq!(pos.get_column(), Some(5));

pub fn set_column(&mut self, col: usize)[src]

Sets the column of this Position. If the current value does not accomodate a column, the enum will be promoted to a value that does.

Examples

use tweep::Position;
let mut pos = Position::default();
assert_eq!(pos, Position::StoryLevel);
pos.set_column(23);
assert_eq!(pos, Position::Column(23));

pub fn get_file(&self) -> Option<&str>[src]

Gets the file name referenced by this Position, if there is one.

Examples

use tweep::Position;
let mut pos = Position::default();
assert_eq!(pos.get_file(), None);
let file_name = "file.ext";
pos.set_file(file_name.to_string());
assert_eq!(pos.get_file(), Some(file_name));

pub fn set_file(&mut self, file: String)[src]

Sets the file name of this Position. If the current value does not accomodate a file name, the enum will be promoted to a value that does. In such a case, the row and column will be set to a default of 1 if they are not already set

Examples

use tweep::Position;
let mut pos = Position::default();
assert_eq!(pos, Position::StoryLevel);
let file_name = "file.ext";
pos.set_file(file_name.to_string());
assert_eq!(pos, Position::File(file_name.to_string(), 1, 1));

pub fn offset_column(&mut self, offset: usize)[src]

Offsets the column of this Position by offset. If it's not currently storing a column, this has the same effect as set_column(offset)

Examples

use tweep::Position;
let mut pos = Position::default();
assert_eq!(pos.get_column(), None);
pos.offset_column(4);
assert_eq!(pos.get_column(), Some(5));
pos.offset_column(5);
assert_eq!(pos.get_column(), Some(10));

pub fn get_row(&self) -> Option<usize>[src]

Gets the row of this Position if one exists.

Examples

use tweep::Position;
let mut pos = Position::default();
assert_eq!(pos.get_row(), None);
pos.set_row(5);
assert_eq!(pos.get_row(), Some(5));

pub fn set_row(&mut self, row: usize)[src]

Sets the row of this Position. If the current value does not accomodate a row, the enum will be promoted to a value that does.

Examples

use tweep::Position;
let mut pos = Position::default();
assert_eq!(pos, Position::StoryLevel);
pos.set_row(23);
assert_eq!(pos, Position::RowColumn(23, 1));

pub fn offset_row(&mut self, offset: usize)[src]

Offsets the row of this Position by offset. If it's not currently storing a row, this has the same effect as set_row(offset)

Examples

use tweep::Position;
let mut pos = Position::default();
assert_eq!(pos.get_row(), None);
pos.offset_row(4);
assert_eq!(pos.get_row(), Some(5));
pos.offset_row(5);
assert_eq!(pos.get_row(), Some(10));

Trait Implementations

impl Clone for Position[src]

impl Debug for Position[src]

impl Default for Position[src]

impl Display for Position[src]

impl Eq for Position[src]

impl PartialEq<Position> for Position[src]

impl StructuralEq for Position[src]

impl StructuralPartialEq for Position[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.