>>106001749yeah like i said
its unnecessarily complicated
and the complexity emerges from the language
heres an implementation of try_map in c for comparison
int try_map(void *array, int (*function)(void *), size_t elem_size , size_t size)
{
while (size--)
{
int error;
if (error = function(array)) // if non equal to 0, short circuits
return(error);
array -+ elem_size;
}
}
its not bigger that rusts' synopsis alone by much
as for the generic part theres tricks to be played
like name mangling through macros
or encoding the type with the data so that you support heterogenous arrays
or even adding a parameter for your iterator
which you could keep a pointer to within your structures if you wanna be fancy
possibilities are endless
but the complexity then emerges from the machinery
not from the syntax
as it should be
bc otherwise its the definition of fighting the language
thats why i dont like rust and think its a bad product
they had a complex idea with encoding good practices into the synatx but its doesnt mean its good
they offset the job of static analysis to the memory of the user. which is extremely lazy, as a product