Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I tried using interior mutability in rui [1] but the clunkiness appeared in having to call clone on the Rc/Arc too often. I'd have a few clones before moving into a closure, like this:

        let text = self.text.clone();
        focus(move |has_focus| {
            let text = text.clone();
            state(TextEditorState::new(), move |state| {
                let text = text.clone();
                let text2 = text.clone();
                let cursor = state.with(|s| s.cursor);
                let state2 = state.clone();
currently looks like this:

    focus(move |has_focus| {
        state(TextEditorState::new, move |state, cx| {
            let cursor = cx[state].cursor;
            canvas(move |cx, rect, vger| {
(Note the context (cx) passed to callbacks to look things up.)

[1] https://github.com/audulus/rui



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: