tui-rs icon indicating copy to clipboard operation
tui-rs copied to clipboard

Use `borrow::Cow` instead of raw reference in widgets property wherever possible

Open sudipghimire533 opened this issue 1 year ago • 0 comments

Problem

Current while constructing widgets, parameter are taken as preference. Eg: While creating Table<'a> we have to pass &'a [Constraint]. This makes is hard to write for example the constraint if we are using helper functions to create widgets. For example, this might be a common use case but is not possible:

fn create_table() -> Table<'a> {
    let widths: [Constaint; 3] = calculate_constaint_for_table();
    Table::new(some_rows).width(widths).block(some_block)
}

Cannot return Table because referenced widths does not live long enough

Solution

Instead receive and use as Table property Cow<'a, [Constraints]> which will user to choose to pass borrowed or owned type

sudipghimire533 avatar Aug 09 '22 03:08 sudipghimire533