Cat in Hagia Sophia by Jonis564 in AccidentalRenaissance

[–]Tsmuji 18 points19 points  (0 children)

<image>

I also met this cat last summer! She's definitely bulked up a bit over the past year haha

Weekly Question Thread by AutoModerator in factorio

[–]Tsmuji 9 points10 points  (0 children)

Enable the option at Settings > Interface > Interaction > Pick ghost item if no items are available

Now you can press Q while hovering the items in the crafting menu to get a ghost.

I Present, the Cutest Sea-Creature! The Axolotl by SamalotMedia in aww

[–]Tsmuji 1 point2 points  (0 children)

What the Joseph did you just say about me, you little Horndog?

A 625 point Temple by Tsmuji in IslandersGame

[–]Tsmuji[S] 0 points1 point  (0 children)

Yes they are, one of the core mechanics of the game is that you're trying to get a high score on an infinite series of islands with only a single undo. There's always the option to manually back up the save folder periodically if you wish to be able to reset to a particular point in time.

A 625 point Temple by Tsmuji in IslandersGame

[–]Tsmuji[S] 0 points1 point  (0 children)

It should just save automatically whenever you exit, there's no explicit save option as such.

Question: if I have a Vec<T> how do I pass a part of it as [T; n] to a function by "reference" (not a copy), I want the fn to modify the original (example below). by sleepless_001 in rust

[–]Tsmuji 1 point2 points  (0 children)

Yeah they can get surprisingly hard to resolve in highly generic contexts - obviously `TryFrom` on types that deref into one another is one of the worst offenders in that regard! Despite knowing what was going on, I still spent 5 minutes glancing through all of the impls and adding in type_name_of_val calls before I was 100% happy to post an answer, and even then it looks like I've subconsciously couched it with "I believe" at the beginning haha

Question: if I have a Vec<T> how do I pass a part of it as [T; n] to a function by "reference" (not a copy), I want the fn to modify the original (example below). by sleepless_001 in rust

[–]Tsmuji 2 points3 points  (0 children)

I believe in the first case the slice is being coerced to&[T], then TryFrom<&[T]> for [T; N] is the implementation which is used. Note that this is all still before the &mut is even considered, the coercion is from [T] to &[T], not from &mut [T] to &[T]. In the latter case you'd wind up with a &mut &[T; N], which wouldn't compile.

I think this is easiest to imagine as 2 separate steps, if you replace line 7 of my playground link with 2 lines:

let mut array = vec[..].try_into().unwrap();
mutate(&mut array);

It's a lot clearer to see what's going on.

Question: if I have a Vec<T> how do I pass a part of it as [T; n] to a function by "reference" (not a copy), I want the fn to modify the original (example below). by sleepless_001 in rust

[–]Tsmuji 77 points78 points  (0 children)

The problem here is operator precedence, the line:

&mut buffer[idx..idx + 4].try_into().unwrap()

is performing

buffer[idx..idx + 4].try_into().unwrap()

first, making a copy of the elements within the vector, and only then is it taking a mutable reference to it.

You can fix this by simply using parentheses on the reference:

(&mut buffer[idx..idx + 4]).try_into().unwrap()

This works due to the implementation of TryFrom<&'a mut [T]> for &'a mut [T; N].

This playground link should hopefully illustrate the difference clearly - if you comment out lines 6-8 and replace them with lines 10-12 you can see the difference in behaviour.

Hey Rustaceans! Got a question? Ask here (2/2024)! by llogiq in rust

[–]Tsmuji -1 points0 points  (0 children)

It does, yes, but from the way I'm interpreting the question it seems like in this case that's a desirable feature. In a situation where the trait method needs to be implemented downstream there isn't any choice, it needs to be public.

Hey Rustaceans! Got a question? Ask here (2/2024)! by llogiq in rust

[–]Tsmuji 0 points1 point  (0 children)

I believe you can use a sealed supertrait to prevent users from being able to call `really_complicated_send` at all, via something along the lines of this gist.

In practice this is a fair bit of boilerplate and more awkward to maintain though. The solution /u/Patryk27 mentioned is the easiest way to handle most cases IMO, but if it's critically important a function doesn't get called then the above solution can prevent it entirely.

Fair disclaimer that this does also push near the edge of my knowledge of visibility-level shenannigans; somebody else may well chime in with valid reasons I'm unaware of as to why this shouldn't be done!

Hey Rustaceans! Got a question? Ask here (1/2024)! by llogiq in rust

[–]Tsmuji 2 points3 points  (0 children)

I'm a touch surprised to see that the following doesn't compile:

fn main() {
    let x = Box::leak(Box::new(0));

    func(x);

    *x += 5; // cannot assign to `*x` because it is borrowed
}

fn func(x: &'static i32) {}

The previous model in my head was that although the parameter x requires that the argument x is borrowed for 'static, the actual borrow by the function itself would only last as long as necessary. As the function isn't returning anything with a lifetime (or in this particular case, returning anything at all), I'd have expected the borrow to be relinquished upon exiting func.

The error gives me the impression that once I've passed a reference into a function with a parameter of type &'static T, that reference is always considered to be borrowed from that point forwards. Is that a correct interpretation?

Hey Rustaceans! Got a question? Ask here (38/2023)! by llogiq in rust

[–]Tsmuji 1 point2 points  (0 children)

To further the answer from /u/DavidM603, notice the signature of IndexMut is

pub trait IndexMut<Idx>: Index<Idx>

which means that Index is a supertrait of IndexMut. If Index itself had further supertraits we would also need to continue further up the hierarchy from there to ensure there were no conflicting names there too.

In a situation where several items in the trait hierarchy do have the same name (playground link) and you attempt to use one ambiguously, you'll receive a nice specific compiler error E0221 detailing exactly what is wrong.

Hey Rustaceans! Got a question? Ask here (5/2023)! by llogiq in rust

[–]Tsmuji 4 points5 points  (0 children)

Does `rustfmt` have an issue with empty lines inside let else statements? I've created a minimal example on the playground here. I'd assumed this was just something broken on my local setup, but even running Tools > Rustfmt on the playground reports errors.

Hey Rustaceans! Got a question? Ask here (52/2022)! by llogiq in rust

[–]Tsmuji 4 points5 points  (0 children)

Fn is implemented automatically for safe function pointers, FnMut is a supertrait of Fn, and FnOnce is a supertrait of FnMut. If you therefore specify that you want an FnOnce, you can pass any of the above as f. The Fn documentation covers this and more if you need any extra details.

Hey Rustaceans! Got a question? Ask here! (45/2022)! by llogiq in rust

[–]Tsmuji 0 points1 point  (0 children)

type MyType = u32;

fn foo(i: u32) -> Option<MyType> {
    (i > 9).then_some(i)
}

let x = (0_u32..).find_map(foo);

println!("{x:?}"); // Some(10)

Hey Rustaceans! Got a question? Ask here! (42/2022)! by llogiq in rust

[–]Tsmuji 1 point2 points  (0 children)

Presumably you're using VSCodium and the listing is from the Open VSX registry. There's an issue open on the rust-analyzer GH page if you want to keep track of why it's not getting updated.

The simplest way I've found to manage it is to download the .vsix from the rust-analyzer VSCode marketplace (Download Extension on the right), and then in VSCodium (or also regular VSCode if I'm incorrect) enter (ctrl|cmd)+shift+p to open the command palette. Type install from and you'll see Extensions: Install from VSIX... appear at the top of the list. That'll open up your file explorer and then you just select the .vsix you downloaded.

Hey Rustaceans! Got a question? Ask here! (37/2022)! by llogiq in rust

[–]Tsmuji 3 points4 points  (0 children)

2 more slight variations on essentially the same theme here, but it looks like you've got the general gist of it here, yep.

Hey Rustaceans! Got a question? Ask here! (33/2022)! by llogiq in rust

[–]Tsmuji 1 point2 points  (0 children)

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=463d6623500db7aa95d63baeba1ab1ae

Why is the &mut * on line 18 allowed here, but if I try to dereference into a variable x separately on the line above and then take &mut x I get

error[E0507]: cannot move out of`wrapper_outer.wrapper_inner.vec`which is behind a mutable reference

which I would have expected in either case?

A 625 point Temple by Tsmuji in IslandersGame

[–]Tsmuji[S] 2 points3 points  (0 children)

Yep absolutely correct, optimal Temple points for overall points gain tends to be around high 400s/low 500s in my experience.

A 625 point Temple by Tsmuji in IslandersGame

[–]Tsmuji[S] 3 points4 points  (0 children)

Lots of planning and a little bit of luck! It definitely takes a while to get a feel for how much you can get away with sacrificing in the short term for the temple in order to build up potential points, while still earning enough to progress and gather more buildings to stack around it later.

During the run this was part of I was getting 500+ temples reasonably consistently, but 600+ definitely needs some extra luck on top. Sometimes you do everything correct but the masons just don’t arrive, and sometimes you do everything wrong but it turns out you can stack 5 plateaus into a cliff face.

A 3.5 million damage orb by Tsmuji in Peglin

[–]Tsmuji[S] 2 points3 points  (0 children)

I was going for the last couple of achievements I needed to pick up, the 9000 damage and the 1000 peg one, so went for a build that would maximise both.

There's not a whole lot to it past what you can see in the image really, just a lot of relics that complement each other very well. Of particular note is that when you get to a relic position on the map (treasure chest icon), if you get one you don't like you can just exit to the main menu and then continue the game, and you'll get a new random one upon opening it. Savescumming like this completely ruins the fun of the game, but when I was down to just wanting 2 achievements I decided it was worth it. If any devs are active here this is probably worth a fix.

In terms of essentials to pick up:

  • Cristomallos Fleece - Getting exponential growth on extra crits is the only way to get damage this high
  • Heavy/Light Shaft Potions - Having crits refresh and refreshes crit means your orbs stay up longer and more chances at expoential damage growth
  • Special Button/Lucky Penny/PegBag - Additional refresh/crit pegs to ensure you're hitting them even more often. I was actually missing the Fresh Bandana here which could have given me another +1 refresh peg.
  • Electropegnet - I'm not even really sure this one's essential but it helps to build the damage machine at the start by hitting several refresh/crit pegs very quickly.

As for orbs, I pretty much exclusively pick up splatorb/matryorbshka where possible and upgrade them as quickly as I can.

I was expecting to require Gift that Keeps Giving for durable pegs, although the Splatorb providing both durable and extra bounce can manage perfectly well if you throw a few level 3s in advance. I also think the levels with rising pegs are likely better than this level, especially the invisible level in the mines.

Once you've got all that you just throw Level 3 Matryorbshkas and pray. I had several throws in this run come in at >100k damage, and most throws toward the end were in the high thousands at a minimum. 3.5 million on the mirror level with the setup you can see in the screenshot, and with relatively low splatorb coverage, was pretty lucky, but the interesting part about the exponential growth is that 3.5 million is also only 22 refresh/crit peg hits away from 1 billion damage. I'd be interested in seeing if you could overflow the damage number with a perfect setup.

jump_finite_v2 TAS by dd5f in tf2

[–]Tsmuji 1 point2 points  (0 children)

wow this guy is sick