#i feel like im doing things too difficult than they should be

29 messages · Page 1 of 1 (latest)

plain hornet
#

(this is the app visually)

worldly crane
#

welcome to immediate mode ui and egui's cursor model

#

honestly i dont see anything super wrong with ur code

plain hornet
#

yeah but like

#

im cloning a whole option type just to use its value

#

at line 63

#

because the compiler doesnt shut up if I try to do it differently

autumn axle
#

there's a nice method on options called as_ref which you could use there

#

if you have &Option<T> it becomes Option<&T>

carmine ocean
plain hornet
#

also I'd like to know if I can make this a reference to one of the Milestone structs that exist in the array right above the selected text without all this weird lifetime stuff

pastel venture
#

you can't.

plain hornet
#

every time I try to use references the compiler tells me that I suck

pastel venture
#

you can't create self-referrential structs in rust without way too much pain.

plain hornet
#

so is storing the index to the selected item the better option here

pastel venture
#

yes

#

Another option is using something like Rc

#

but i personally think index is nicer

plain hornet
#

I'm not familiar with these container types yet

#

that's also why I'm having so many issues with this Option thing

autumn axle
#

std's pretty deep for how narrow it is, things get more familiar with time trust me

plain hornet
#

it makes sense in my head but in code nothing works

pastel venture
#

i should probably also mention that Rc has a bunch of its own issues, and you would probably need to do something silly like Rc<RWLock<Milestone>> which is.. not really any easier to work with than the index.

pastel venture
# plain hornet that's also why I'm having so many issues with this Option thing

I suggest opening the Option docs page https://doc.rust-lang.org/std/option/enum.Option.html
and reading it in full once. You don't need to memorize anything, just read. Just once. Simply to have a vague idea that these methods exist next time you need something of the sort, and so that you can look them up in more detail if neccessary.
You can do the same for Result.

#

.. and maaaaybe Iterator if you feel up to it.

plain hornet