Guide API
Skip to main content

StringList

Struct StringList 

Source
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

Source

pub fn new() -> Self

Create an empty StringList.

Source

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);
Source

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, "");
Source

pub fn len(&self) -> usize

Number of entries in this StringList.

Source

pub fn is_empty(&self) -> bool

true when the StringList contains no entries.

Trait Implementations§

Source§

impl Default for StringList

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S: Into<String>> FromIterator<(u16, S)> for StringList

Source§

fn from_iter<I: IntoIterator<Item = (u16, S)>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.