[−][src]Struct genie::LangFile
A mapping of StringKey
key to String
values.
May be read from or written to one of the three file formats for Aoe2 language files.
Methods
impl LangFile
[src]
pub fn read_dll<impl Read>(&mut self, input: impl Read) -> Result<(), LoadError> where
impl Read: Read,
[src]
impl Read: Read,
Reads a language file from a .DLL. This function eagerly loads all the strings into memory.
Returns Err(e)
where e
is a LoadError
if an error occurs while
loading the file.
pub fn write_to_ini<W>(&self, output: &mut W) -> Result<(), Error> where
W: Write,
[src]
W: Write,
Writes this language file to an output writer using the ini format.
pub fn write_to_keyval<W>(&self, output: &mut W) -> Result<(), Error> where
W: Write,
[src]
W: Write,
Writes this language file to an output writer using the key-value format.
pub fn new() -> LangFile
[src]
pub fn is_empty(&self) -> bool
[src]
Returns true
if this language file contains no key-value pairs,
false
otherwise.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); assert!(lang_file.is_empty()); lang_file.insert(StringKey::from(0), String::from("")); assert!(!lang_file.is_empty());
pub fn len(&self) -> usize
[src]
Returns the number of key-value pairs in this language file.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); assert_eq!(0, lang_file.len()); lang_file.insert(StringKey::from(0), String::from("")); assert_eq!(1, lang_file.len());
pub fn clear(&mut self)
[src]
Removes all key-value pairs from this Language file.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("")); lang_file.clear(); assert!(lang_file.is_empty());
pub fn drain(&mut self) -> Drain<StringKey, String>
[src]
Clears this Language file, returning all key-value pairs as an iterator.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("a")); lang_file.insert(StringKey::from(1), String::from("b")); for (k, v) in lang_file.drain().take(1) { assert!(k == StringKey::from(0) || k == StringKey::from(1)); assert!(v == "a" || v == "b"); } assert!(lang_file.is_empty());
pub fn contains_key(&self, k: &StringKey) -> bool
[src]
Returns true
if the map contains a value for key k
, false
if not.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("")); assert!(lang_file.contains_key(&StringKey::from(0))); assert!(!lang_file.contains_key(&StringKey::from(1)));
pub fn get(&self, k: &StringKey) -> Option<&String>
[src]
Returns a reference to the value corresponding to the key.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("")); assert_eq!(Some(&String::from("")), lang_file.get(&StringKey::from(0))); assert_eq!(None, lang_file.get(&StringKey::from(1)));
pub fn get_mut(&mut self, k: &StringKey) -> Option<&mut String>
[src]
Returns a mutable reference to the value corresponding to the key.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("a")); if let Some(s) = lang_file.get_mut(&StringKey::from(0)) { s.push('A'); } assert_eq!("aA", lang_file.get(&StringKey::from(0)).unwrap());
pub fn entry(&mut self, key: StringKey) -> Entry<StringKey, String>
[src]
Returns the given key's corresponding entry in the language file.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("a")); let s0 = lang_file.entry(StringKey::from(0)) .or_insert(String::from("Hello")); s0.push('A'); let s1 = lang_file.entry(StringKey::from(1)) .or_insert(String::from("Hello")); s1.push('A'); assert_eq!("aA", lang_file.get(&StringKey::from(0)).unwrap()); assert_eq!("HelloA", lang_file.get(&StringKey::from(1)).unwrap());
pub fn insert(&mut self, k: StringKey, v: String) -> Option<String>
[src]
Inserts a key-value pair into this language file.
Returns None
. if the language file did not have the key present.
If the key was present, the value is updated, and the old value is returned.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("a")); assert!(!lang_file.is_empty()); lang_file.insert(StringKey::from(0), String::from("b")); assert_eq!(Some(String::from("b")), lang_file.insert(StringKey::from(0), String::from("c")));
pub fn remove(&mut self, k: &StringKey) -> Option<String>
[src]
Removes a key-value pair from the map, returning the value at the key
if the key was previously in the map.
Returns None
if the key was not in the map.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("")); assert_eq!(Some(String::from("")), lang_file.remove(&StringKey::from(0))); assert_eq!(None, lang_file.remove(&StringKey::from(0)));
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&StringKey, &mut String) -> bool,
[src]
F: FnMut(&StringKey, &mut String) -> bool,
Retains only the elements specified by the predicate.
In other words, removes all pairs (k, v)
such that f(&k, &mut v)
returns false
.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::from(1), String::from("one")); lang_file.insert(StringKey::from("2"), String::from("two")); lang_file.retain(|k, _| match k { StringKey::Num(_) => true, StringKey::Name(_) => false, }); assert_eq!(3, lang_file.len());
pub fn iter(&self) -> Iter<StringKey, String>
[src]
An iterator visiting all key-value pairs in an arbitrary order.
The iterator element type is (&'a StringKey, &'a String)
.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::from(1), String::from("one")); lang_file.insert(StringKey::from("2"), String::from("two")); for (k, v) in lang_file.iter() { println!("key: {}, val: {}", k, v); }
pub fn iter_mut(&mut self) -> IterMut<StringKey, String>
[src]
Returns an iterator that visits all key-values pairs in an arbitrary
order, with mutable references to the values.
The iterator element type is (&'a StringKey, &'a mut String)
.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::from(1), String::from("one")); lang_file.insert(StringKey::from("2"), String::from("two")); for (_, v) in lang_file.iter_mut() { v.push('A'); } for (k, v) in &lang_file { println!("key: {}, val: {}", k, v); }
pub fn keys(&self) -> Keys<StringKey, String>
[src]
Returns an iterator that visits all keys in arbitrary order.
The iterator element type is &'a StringKey
.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::from(1), String::from("one")); lang_file.insert(StringKey::from("2"), String::from("two")); for k in lang_file.keys() { println!("key: {}", k); }
pub fn values(&self) -> Values<StringKey, String>
[src]
Returns an iterator that visits all values in arbitrary order.
The iterator element type is &'a String
.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::from(1), String::from("one")); lang_file.insert(StringKey::from("2"), String::from("two")); for v in lang_file.values() { println!("value: {}", v); }
pub fn values_mut(&mut self) -> ValuesMut<StringKey, String>
[src]
Returns an iterator visiting all values mutable in arbitrary order.
The iterator element type is &'a mut String
.
Examples
use genie_lang::{LangFile, StringKey}; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::from(0), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::from(1), String::from("one")); lang_file.insert(StringKey::from("2"), String::from("two")); for v in lang_file.values_mut() { v.push('A'); } for v in lang_file.values() { println!("{}", v); }
Trait Implementations
impl PartialEq<LangFile> for LangFile
[src]
impl Default for LangFile
[src]
impl<'_> Index<&'_ StringKey> for LangFile
[src]
type Output = String
The returned type after indexing.
fn index(&self, key: &StringKey) -> &String
[src]
impl Debug for LangFile
[src]
impl Extend<(StringKey, String)> for LangFile
[src]
impl Clone for LangFile
[src]
fn clone(&self) -> LangFile
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a> IntoIterator for &'a LangFile
[src]
type Item = (&'a StringKey, &'a String)
The type of the elements being iterated over.
type IntoIter = Iter<'a, StringKey, String>
Which kind of iterator are we turning this into?
fn into_iter(self) -> <&'a LangFile as IntoIterator>::IntoIter
[src]
impl IntoIterator for LangFile
[src]
type Item = (StringKey, String)
The type of the elements being iterated over.
type IntoIter = IntoIter<StringKey, String>
Which kind of iterator are we turning this into?
fn into_iter(self) -> <LangFile as IntoIterator>::IntoIter
[src]
impl<'a> IntoIterator for &'a mut LangFile
[src]
type Item = (&'a StringKey, &'a mut String)
The type of the elements being iterated over.
type IntoIter = IterMut<'a, StringKey, String>
Which kind of iterator are we turning this into?
fn into_iter(self) -> <&'a mut LangFile as IntoIterator>::IntoIter
[src]
impl Eq for LangFile
[src]
impl FromIterator<(StringKey, String)> for LangFile
[src]
impl Display for LangFile
[src]
Auto Trait Implementations
impl Sync for LangFile
impl Unpin for LangFile
impl Send for LangFile
impl UnwindSafe for LangFile
impl RefUnwindSafe for LangFile
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,