#i feel like im doing things too difficult than they should be
29 messages · Page 1 of 1 (latest)
welcome to immediate mode ui and egui's cursor model
honestly i dont see anything super wrong with ur code
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
there's a nice method on options called as_ref which you could use there
if you have &Option<T> it becomes Option<&T>
you generally need to clone strings if you want to use them in multiple places at once. A lot of functions wants mutable access to strings, and a String is a mutable reference to a string slice, &str.
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
you can't.
every time I try to use references the compiler tells me that I suck
you can't create self-referrential structs in rust without way too much pain.
so is storing the index to the selected item the better option here
yes
Another option is using something like Rc
A single-threaded reference-counting pointer. ‘Rc’ stands for ‘Reference Counted’.
but i personally think index is nicer
I'm not familiar with these container types yet
that's also why I'm having so many issues with this Option thing
std's pretty deep for how narrow it is, things get more familiar with time trust me
it makes sense in my head but in code nothing works
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.
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.
The Option type. See the module level documentation for more.
.. and maaaaybe Iterator if you feel up to it.
and what about slightly wrong?
ill read it now