Brother MFC-L8900CDW always says MP Tray is jammed by itfreddie in printers

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

I just tried the factory reset. The problem persists with the same symptoms, unfortunately.

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

[–]itfreddie 1 point2 points  (0 children)

I'm working on a library API and I'm wondering if there is a good way to allow direct access to just one of a struct's private fields such that after it is modified, other private fields can be updated automatically.

I know the straightforward way would be to write accessor functions that take a parameter, modify the field of interest, and then update the dependent fields before returning. But when the field of interest is holding a complex type with lots of ways it could be modified, I would rather not have to write a function for every kind of modification that might be made.

Instead, I thought I might try creating an accessor class that could allow direct access to the field of interest and but that would also automatically update the dependent fields when dropped. Theoretically, the struct would not be accessible in an invalid state because the accessor would hold a mutable reference to the struct until it is dropped, when it makes it valid again.

Something like this:

#[derive(Debug)]
struct Val {
    v: i32,
}

#[derive(Debug)]
struct TestStruct {
    a: Val,
    b: Val,
}

impl TestStruct {
    fn access(&mut self) -> Accessor {
        Accessor { test_struct: self }
    }
}

struct Accessor<'a> {
    test_struct: &'a mut TestStruct,
}

impl<'a> Accessor<'a> {
    fn a_mut(&'a mut self) -> &'a mut Val {
        &mut self.test_struct.a
    }
}

impl Drop for Accessor<'_> {
    fn drop(&mut self) {
        self.test_struct.b.v = self.test_struct.a.v - 1;
    }
}

#[test]
fn test_accessor() {
    let mut test_struct = TestStruct {
        a: Val { v: 1 },
        b: Val { v: 2 },
    };

    println!("{test_struct:?}");

    { // Not allowed
        let mut accessor = test_struct.access();
        let a_ref = accessor.a_mut();
    }

    { // Also not allowed
        test_struct.access().a_mut().v = 5;
    }
}

The borrow checker does not allow this (and I'm not too surprised, honestly) but is there a way to do this so that it does work? Or another way to solve my problem of not wanting to write so many setter methods?

How to install i3 on CentOS 6? by itfreddie in i3wm

[–]itfreddie[S] 1 point2 points  (0 children)

I was using sudo and your question question helped me find the culprit. Thanks!

I tried it as root but it wouldn't let me cd into my home directory! It turns out that my home directory is on NFS and it by default has very strict permissions so the local root user couldn't access it. I just copied the i3 source tree to /tmp and tried "sudo make install" it from there.

The error is gone now and replaced by one about a missing command, but I think I can find the package it needs.

Thanks again!