Struct sharecart1000::Sharecart[][src]

pub struct Sharecart {
    pub map_x: u16,
    pub map_y: u16,
    pub misc: [u16; 4],
    pub player_name: String,
    pub switch: [bool; 8],
}

This is your Sharecart data, in a rusty form.

Fields

map_x: u16

This should be 0-1023 (10 bits).

  • Saving: Ignores the high bits (eg: cart.map_x % 1024)
  • Loading: Attempts to parse a u16 (0 on failure), and then truncates to 10 bits.
map_y: u16

This should be 0-1023 (10 bits).

  • Saving: Ignores the high bits (eg: cart.map_y % 1024)
  • Loading: Attempts to parse a u16 (0 on failure), and then truncates to 10 bits.
misc: [u16; 4]

Misc data.

  • Saving: The full range is supported
  • Loading: Attempts to parse a u16, uses 0 on failure.
player_name: String

The player’s name, or something like it.

The definition of “1023chars” is slightly fuzzy when you get into the fact that there’s multi-byte characters, but that some languages assume all chars are 1 byte. While we’re working with it in memory, we just act like it’s a normal String value. If you’re just using this field for 1,023 or fewer ASCII characters (without line endings), you’ll be totally fine. Otherwise there’s some edge cases to worry about.

  • Saving: Filters out any '\r', and '\n', takes the first 1023 bytes of what’s left, lossy re-parses as utf-8 to make sure there was no partial byte sequences at the end, and then strips any '\u{0FFFD}'.
  • Loading: Same as with saving.
switch: [bool; 8]

The eight switches.

  • Saving: Always outputs as “TRUE” or “FALSE”.
  • Loading: Ignores case, so that “True” and “TrUe” and such are also allowed as true. Any value that isn’t read as true becomes false.

Implementations

impl Sharecart[src]

pub fn from_str<S: AsRef<str>>(buf: S) -> Self[src]

Parses the string given into a Sharecart value.

You will always get a Sharecart of some sort back. If any individual field is missing, then you’ll get the Default value in that field. If the “[Main]” section is missing then you’ll get the default value in every field. If the string somehow can’t even be parsed at all then you’ll get the default value in every field. Field names ignore capitalization differences.

Note: the contents of the o_o.ini file might not be valid utf-8, so as you read it from disk to pass into this function you’ll have to decide how you want to handle that possibility. I’d suggest you use String::from_utf8_lossy, but it’s up to you.

use sharecart1000::Sharecart;

let mut sc = Sharecart::default();
assert_eq!(sc, Sharecart::from_str(""));
assert_eq!(sc, Sharecart::from_str("[Main]"));

sc.map_x = 73;
sc.map_y = 1023;
assert_eq!(sc, Sharecart::from_str(r#"[Main]
MapX=73
MapY=1023"#));

sc.misc[0] = 54;
sc.misc[1] = 540;
sc.misc[2] = 999;
sc.misc[3] = ::std::u16::MAX;
sc.player_name = "Fearless Concurrency".to_string();
let mut foo = true;
for i in 0 .. 8 {
  sc.switch[i] = foo;
  foo = !foo;
}
assert_eq!(sc, Sharecart::from_str(sc.to_string()));

pub fn to_string(&self) -> String[src]

Gives you a String that you can write into the o_o.ini file.

The string includes the “[Main]” section tag and other proper ini formatting, so that you can completely replace the current o_o.ini contents with this new string when saving the game.

Lines are always separated by the '\n' character, even on Windows. If you would like to use the “\r\n” windows-style line break sequence instead, please use the replace method on the output string (eg: sc.to_string().replace("\n", "\r\n")).

use sharecart1000::Sharecart;
assert_eq!(Sharecart::default().to_string(), r#"[Main]
MapX=0
MapY=0
Misc0=0
Misc1=0
Misc2=0
Misc3=0
PlayerName=
Switch0=FALSE
Switch1=FALSE
Switch2=FALSE
Switch3=FALSE
Switch4=FALSE
Switch5=FALSE
Switch6=FALSE
Switch7=FALSE
"#);

Trait Implementations

impl Clone for Sharecart[src]

impl Debug for Sharecart[src]

impl Default for Sharecart[src]

impl Eq for Sharecart[src]

impl Hash for Sharecart[src]

impl Ord for Sharecart[src]

impl PartialEq<Sharecart> for Sharecart[src]

impl PartialOrd<Sharecart> for Sharecart[src]

impl StructuralEq for Sharecart[src]

impl StructuralPartialEq for Sharecart[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, 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.