pub struct StringList { /* private fields */ }Expand description
A keyed lookup of strings (u16 key → String).
Backed by a BTreeMap<u16, String>, so iteration is in ascending key order.
A missing key returns None (callers that want an empty-string fallback can
use .unwrap_or("")).
§Turbo Vision heritage
Ports TStringList / TStrListMaker (tstrlist.cpp). The original classes
exist entirely to serialize a compressed keyed-string table to/from a
resource (.res) stream; tvision-rs drops that streaming/persistence machinery
(TStrIndexRec, the run-length index, the byte-length-prefixed blob, and
build/read/write) and keeps only the observable contract — a keyed
lookup of strings (deviation D12). The maker/list split, which existed only
for the write-vs-read streaming asymmetry, collapses into one type.
Implementations§
Source§impl StringList
impl StringList
Sourcepub fn insert(&mut self, key: u16, value: impl Into<String>)
pub fn insert(&mut self, key: u16, value: impl Into<String>)
Associate value with key, overwriting any previous entry for that key.
Use this to build a StringList at startup (the equivalent of
TStrListMaker::Put from Turbo Vision). Keys are arbitrary u16 values;
iteration and lookup are in ascending key order.
use tvision_rs::text::StringList;
let mut list = StringList::new();
list.insert(10, "Open");
list.insert(20, "Save");
list.insert(10, "Open…"); // overwrite key 10
assert_eq!(list.get(10), Some("Open…"));
assert_eq!(list.len(), 2);Sourcepub fn get(&self, key: u16) -> Option<&str>
pub fn get(&self, key: u16) -> Option<&str>
Look up the string stored under key, returning a borrowed slice, or
None when no entry exists for that key.
Use this to display or process a string identified by a numeric key — for example, to retrieve a help message at runtime:
use tvision_rs::text::StringList;
let mut list = StringList::new();
list.insert(1, "File not found");
assert_eq!(list.get(1), Some("File not found"));
assert_eq!(list.get(99), None);
// Callers that need an empty-string fallback for missing keys:
let msg = list.get(99).unwrap_or("");
assert_eq!(msg, "");Trait Implementations§
Source§impl Default for StringList
impl Default for StringList
Source§impl<S: Into<String>> FromIterator<(u16, S)> for StringList
impl<S: Into<String>> FromIterator<(u16, S)> for StringList
Auto Trait Implementations§
impl Freeze for StringList
impl RefUnwindSafe for StringList
impl Send for StringList
impl Sync for StringList
impl Unpin for StringList
impl UnsafeUnpin for StringList
impl UnwindSafe for StringList
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.