Add ability to replace an item in a select view#768
Add ability to replace an item in a select view#768squaresurf wants to merge 1 commit intogyscos:mainfrom
Conversation
|
Hi, and thanks for the PR! Could I'm fine adding this method, if only for the |
I'm not sure why, but I couldn't seem to get a mutable reference properly where the compiler allowed me to mutate the references. Then I realized that I didn't care about the old values and just need an efficient way to replace an item.
Great idea. I'm happy to make this change.
I like this as it feels consistent with other set_item type APIs. I gave it a shot, but it turns out to be a bit complicated to return the values within the |
Do you mind explaining what you mean by this convenience? I'm not sure I understand this. |
I'd be fine with a
Here's how you can currently get mutable references to the label and content of a let mut v = cursive::views::SelectView::new()
.item_str("Foo")
.item_str("Bar");
let (label, content) = v.get_item_mut(1).unwrap();
*label = "foo".into();
*content = "foooo".into(); Here
Once way is to simply return the pub fn replace_item<S>(&mut self, id: usize, label: S, value: T) -> (StyledString, Arc<T>)
where
S: Into<StyledString>,
{
let prev = std::mem::replace(&mut self.items[id], Item::new(label.into(), value));
self.last_required_size = None;
(prev.label, prev.value)
} Another option is to use |
This is a more efficient way to replace an item than calling
remove_item, theninsert_item