skeleton of merge functionality
This commit is contained in:
24
src/lib.rs
24
src/lib.rs
@@ -37,11 +37,12 @@ use std::fmt::Display;
|
||||
use text::{Font, TextDirection};
|
||||
use tile::Tile;
|
||||
use variable::Variable;
|
||||
use std::num::ParseIntError;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Instance {
|
||||
position: Position,
|
||||
id: String, // item / ending.rs id
|
||||
id: String, // item / ending id
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
@@ -75,8 +76,8 @@ impl AnimationFrames for Vec<Image> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_base36(str: &str) -> u64 {
|
||||
u64::from_str_radix(str, 36).expect(&format!("Invalid base36 string: {}", str))
|
||||
fn from_base36(str: &str) -> Result<u64, ParseIntError> {
|
||||
u64::from_str_radix(str, 36)
|
||||
}
|
||||
|
||||
/// this doesn't work inside ToBase36 for some reason
|
||||
@@ -171,11 +172,14 @@ fn new_unique_id(mut ids: Vec<String>) -> String {
|
||||
let mut new_id: u64 = 0;
|
||||
|
||||
for id in ids {
|
||||
if new_id != from_base36(&id) {
|
||||
break;
|
||||
}
|
||||
let id= from_base36(&id);
|
||||
if id.is_ok() {
|
||||
if new_id != id.unwrap() {
|
||||
break;
|
||||
}
|
||||
|
||||
new_id += 1;
|
||||
new_id += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return to_base36(new_id);
|
||||
@@ -209,9 +213,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_from_base36() {
|
||||
assert_eq!(from_base36("0"), 0);
|
||||
assert_eq!(from_base36("0z"), 35);
|
||||
assert_eq!(from_base36("11"), 37);
|
||||
assert_eq!(from_base36("0").unwrap(), 0);
|
||||
assert_eq!(from_base36("0z").unwrap(), 35);
|
||||
assert_eq!(from_base36("11").unwrap(), 37);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user