mikecargal

mikecargal

I get different results on puzzle 15

Rust Brain Teasers: description (Puzzle15: To Infinity)

On this line:

  fn fmt(&self, f: &mut fmt::Formatter<`_>) -> fmt::Result {

Formatter<`_> is flagged as an error (“this struct takes 0 generic arguments but 1 generic argument was supplied”).

When I “correct” it to f: &mut fmt::Formatter then the program runs just fine) only spits out one line and exits normally. It does not spit out node after node until it gets a stack overflow.

I do get a “dead code” warning on the prev property of Node, so maybe that’s being optimized out, thus avoiding your error?

Full source for reference:

use std::cell::RefCell;
use std::rc::Rc;

type Link = Option<Rc<RefCell<Node>>>;

// #[derive(Debug)]
struct Node {
    elem: i32,
    next: Link,
    prev: Link,
}

impl Node {}

use std::fmt;
impl fmt::Debug for Node {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "elem: {}", self.elem)
    }
}

fn main() {
    let mut head = Some(Rc::new(RefCell::new(Node {
        elem: 1,
        next: None,
        prev: None,
    })));
    head.as_mut().unwrap().borrow_mut().next = Some(Rc::new(RefCell::new(Node {
        elem: 2,
        next: None,
        prev: head.clone(),
    })));
    println!("{:?}", head);
}

also for reference:

rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/mike/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin

installed targets for active toolchain
--------------------------------------

wasm32-unknown-unknown
x86_64-apple-darwin

active toolchain
----------------

stable-x86_64-apple-darwin (default)
rustc 1.55.0 (c8dfcfe04 2021-09-06)

First Post!

herbert

herbert

Author of Hands-on Rust

Thanks! I’ve added that to the tracker. This is an odd one, I think an update changed some behavior - because I’m now getting a different result on my travel laptop (I’m taking a short holiday) and remote controlling my work setup. I’ll investigate further for B2. I’m leaning towards a source control merge issue, it looks like I have a branch merged on my work setup and not on the travel laptop - the source isn’t quite the same.

Popular Pragmatic Bookshelf topics Top

Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File &gt; New Rule: And select Deny, O...
New
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New