From 53aea8e91cb6c48e2dee8eaf0a8373a48719614a Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 2 Oct 2016 15:03:03 -0700 Subject: [PATCH] Derive `Clone` for `RadioGroup` Also remove broken example. --- src/views/radio.rs | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/views/radio.rs b/src/views/radio.rs index 3cdf6f4..e16531a 100644 --- a/src/views/radio.rs +++ b/src/views/radio.rs @@ -23,24 +23,13 @@ impl SharedState { /// /// A `RadioGroup` is used to create and manage [`RadioButton`]s. /// +/// A `RadioGroup` can be cloned; it will keep pointing to the same group. +/// /// [`RadioButton`]: struct.RadioButton.html -/// -/// # Examples -/// -/// ``` -/// let mut group = RadioGroup::new(); -/// -/// let button_1 = group.button_str(1, "Option 1"); -/// let button_2 = group.button_str(2, "Option 2"); -/// let button_3 = group.button_str(3, "Option 3"); -/// ``` +#[derive(Clone)] pub struct RadioGroup { // Given to every child button state: Rc>>, - - // Count the number of children already created, - // to give an ID to the next child. - count: usize, } impl RadioGroup { @@ -51,7 +40,6 @@ impl RadioGroup { selection: 0, values: Vec::new(), })), - count: 0, } } @@ -60,10 +48,9 @@ impl RadioGroup { /// The button will display `label` next to it, and will embed `value`. pub fn button>(&mut self, value: T, label: S) -> RadioButton { + let count = self.state.borrow().values.len(); self.state.borrow_mut().values.push(Rc::new(value)); - let result = - RadioButton::new(self.state.clone(), self.count, label.into()); - self.count += 1; + let result = RadioButton::new(self.state.clone(), count, label.into()); result }