[−][src]Struct genie_lang::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.
Implementations
impl LangFile
[src]
pub fn write_to_ini<W: Write>(&self, output: &mut W) -> Result<()>
[src]
Writes this language file to an output writer using the ini format.
pub fn write_to_keyval<W: Write>(&self, output: &mut W) -> Result<()>
[src]
Writes this language file to an output writer using the key-value format.
pub fn new() -> Self
[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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); assert!(lang_file.is_empty()); lang_file.insert(StringKey::try_from(0).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); assert_eq!(0, lang_file.len()); lang_file.insert(StringKey::try_from(0).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("a")); lang_file.insert(StringKey::try_from(1).unwrap(), String::from("b")); for (k, v) in lang_file.drain().take(1) { assert!(k == StringKey::try_from(0).unwrap() || k == StringKey::try_from(1).unwrap()); 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("")); assert!(lang_file.contains_key(&StringKey::try_from(0).unwrap())); assert!(!lang_file.contains_key(&StringKey::try_from(1).unwrap()));
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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("")); assert_eq!(Some(&String::from("")), lang_file.get(&StringKey::try_from(0).unwrap())); assert_eq!(None, lang_file.get(&StringKey::try_from(1).unwrap()));
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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("a")); if let Some(s) = lang_file.get_mut(&StringKey::try_from(0).unwrap()) { s.push('A'); } assert_eq!("aA", lang_file.get(&StringKey::try_from(0).unwrap()).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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("a")); let s0 = lang_file.entry(StringKey::try_from(0).unwrap()) .or_insert(String::from("Hello")); s0.push('A'); let s1 = lang_file.entry(StringKey::try_from(1).unwrap()) .or_insert(String::from("Hello")); s1.push('A'); assert_eq!("aA", lang_file.get(&StringKey::try_from(0).unwrap()).unwrap()); assert_eq!("HelloA", lang_file.get(&StringKey::try_from(1).unwrap()).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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("a")); assert!(!lang_file.is_empty()); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("b")); assert_eq!(Some(String::from("b")), lang_file.insert(StringKey::try_from(0).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("")); assert_eq!(Some(String::from("")), lang_file.remove(&StringKey::try_from(0).unwrap())); assert_eq!(None, lang_file.remove(&StringKey::try_from(0).unwrap()));
pub fn retain<F: FnMut(&StringKey, &mut String) -> bool>(&mut self, f: F)
[src]
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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::try_from(1).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::try_from(1).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::try_from(1).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::try_from(1).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::try_from(1).unwrap(), 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}; use std::convert::TryFrom; let mut lang_file = LangFile::new(); lang_file.insert(StringKey::try_from(0).unwrap(), String::from("zero")); lang_file.insert(StringKey::from("a"), String::from("a")); lang_file.insert(StringKey::try_from(1).unwrap(), 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 Clone for LangFile
[src]
impl Debug for LangFile
[src]
impl Default for LangFile
[src]
impl Display for LangFile
[src]
impl Eq for LangFile
[src]
impl Extend<(StringKey, String)> for LangFile
[src]
impl FromIterator<(StringKey, String)> 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 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) -> Self::IntoIter
[src]
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) -> Self::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) -> Self::IntoIter
[src]
impl PartialEq<LangFile> for LangFile
[src]
impl StructuralEq for LangFile
[src]
impl StructuralPartialEq for LangFile
[src]
Auto Trait Implementations
impl RefUnwindSafe for LangFile
impl Send for LangFile
impl Sync for LangFile
impl Unpin for LangFile
impl UnwindSafe for LangFile
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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> 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, 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>,