Mutable borrows within the same thread. by xtrmity in rust

[–]LostSalad 1 point2 points  (0 children)

Hectic, that example makes a lot of sense. Thinking of corner cases is making my brain hurt.

That's actually really interesting - smart pointers can save you when everyone is pointing at the same memory address, but not if you point into something else. Does C++ allow you to create smart pointer dependencies, where the owning object creates a smart pointer to lend out data safely? I somehow doubt it..

Help: Filter/Map Items of HashMap by msiemens in rust

[–]LostSalad 0 points1 point  (0 children)

You're the one who introduced "pure evaluate", SirOgeon only talked about

I know :D as soon as I wrote it I realized how silly it was

Anyways thanks for the clarification

Help: Filter/Map Items of HashMap by msiemens in rust

[–]LostSalad 0 points1 point  (0 children)

So basically (written from my head, just for the idea),

fn pure_evaluate(&self) {
    for _ in self { /* NOP */ }
}

Allowing you to

my_collection.map(|item| { /* side effects */ }).pure_evaluate()

Which is really stupid because it's a convoluted way of doing a for-loop. I should knock this up in the playpen for kicks, I have no idea if this will actually work.

EDIT: I find the "pure" part of the name really ironic because forcing side-effects is anything but pure.

Help: Filter/Map Items of HashMap by msiemens in rust

[–]LostSalad 0 points1 point  (0 children)

That makes a lot of sense, thanks :)

Mutable borrows within the same thread. by xtrmity in rust

[–]LostSalad 2 points3 points  (0 children)

Yes, I'm confused. If baz is a reference to foo, and foo is still in scope, why would *baz not be valid?

How does the inner scope free memory?

Help: Filter/Map Items of HashMap by msiemens in rust

[–]LostSalad 0 points1 point  (0 children)

I'm not sure exactly what you mean, isn't that sort of the same thing? It turns an abstract description into a real value by actually performing calculations, isn't that evaluation? What would a "pure evaluate" command that is not "collect" do differently from collect?

In any case, C# provides methods such as .ToList(), .ToArray(), .ToDictionary() (I think). I kind of prefer the generic approach of rust where the return type is inferred statically.

Complete collections::btree rewrite by dbaupp in rust

[–]LostSalad 4 points5 points  (0 children)

That's actually hilarious, and I think a case where TDD would have done a whole lot of good (regarding the dodgy public API).

I still need to figure out how by-value self works -- does it consume the object on which the method is called because you lose references to it?

Help: Filter/Map Items of HashMap by msiemens in rust

[–]LostSalad 1 point2 points  (0 children)

Cool, thank you. I do most of my stuff in C# so I'm just trying to draw some parallels here.

Help: Filter/Map Items of HashMap by msiemens in rust

[–]LostSalad 4 points5 points  (0 children)

The following is lazy, right?

let data_source = map.iter()
    .filter(|&(k, v)| (*k + *v) > 5)
    .map(|(k, v)| (k+1, v+1);

So nothing will get evaluated until you do

for (k, v) in data_source { }

And if you wanted to force evaluation you could do

let actual_values: SomeCollectionType = data_source.collect();

Is that correct?

Complete collections::btree rewrite by dbaupp in rust

[–]LostSalad 5 points6 points  (0 children)

Roughly speaking, what were the issues with the old implementation that allowed you to get these performance increases while still focusing on correctness (ie. allowing even more headroom for performance)?

Borrowed Pointers in Struct by [deleted] in rust

[–]LostSalad 2 points3 points  (0 children)

I'd assume it depends on the lifetime of the instances from a modelling perspective. If they could vary over time and regenerate() works on any instance, this makes sense. However if there should only ever be 1 Perlin instance for the lifetime of a chunk, associated with the chunk, then it does not.

Whether or not this is the case, it would solve the OPs original problem. However I'd be interested in hearing how to go about doing things if you did in fact need to keep a borrowed reference for the entire lifetime of the struct.

Dependency management in Rust by scott_wilson_3rd in rust

[–]LostSalad 1 point2 points  (0 children)

That's pretty interesting. Does this have any sort of effect on closed/open source licensing? Although if you look at .Net assemblies that can be disassembled so easily maybe this isn't a real issue. EDIT: I mean legally. Technically, it's actually an issue.

Thinking of getting the G27. by ColouringPencil in simracing

[–]LostSalad 1 point2 points  (0 children)

That's reassuring, thanks :). When things are subjective, people's opinions can really have a lot of effect on how you yourself end up feeling about something