implicit-clone icon indicating copy to clipboard operation
implicit-clone copied to clipboard

Possibly add utility extension traits for quick conversion into immutable types

Open kirillsemyonkin opened this issue 10 months ago • 3 comments

Add to_istring() and similar methods to applicable types, so that it is possible to use a more precise method than into(), without using path-ful calls like IString::from(Rc::from(...)).

May aid with #56, but it might also have the implementation collision akin to having both From<&'static str> and From<&'a str>. In this case it might be probable to make the two do different behaviors: .to_istring() would be always cloning/copying, and would always turn &'static str into an IString::Rc. Also consider even more precise to_istring_static and to_istring_rc (these method names might be too verbose).

Also consider .collect_iarray() and similar, akin to itertools's collect_vec.

kirillsemyonkin avatar Mar 01 '25 14:03 kirillsemyonkin

I'm not really in favor of adding traits because it feels unnecessary but I won't oppose it. implicit-clone is in alpha and if you think this can bring value I think we should try. Worst case scenario we will remove it at the next alpha or before the first stable release.

cecton avatar Mar 03 '25 14:03 cecton

I just had to add those extension traits in my code using ImplicitClone structures, probably because .into() was not reliable enough. Also helps users to not do str.to_string().into() (when an Rc::from(str).into() would be desired) and do str.to_istring() immediately (although that may be resolved if you make .into() work on any &str anyway)

kirillsemyonkin avatar Mar 03 '25 14:03 kirillsemyonkin

I've never really bothered that much about performances but I understand the struggle. I did try a few times to convert an &str to an IString and everytime it feels like something that you should be able to do easily instead of being lead into a not optimal solution.

cecton avatar Mar 03 '25 15:03 cecton