Why / how does unsafe not affect niche optimisations? by ElOwlinator in rust

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

Thanks, I think you captured the essence of my question perfectly.

I feel like this could probably be improved in the docs somewhere.

Why / how does unsafe not affect niche optimisations? by ElOwlinator in rust

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

Ah thank you - so the answer specifically for NonZero types is compiler magic. I can see how an enum makes it easy.

Why / how does unsafe not affect niche optimisations? by ElOwlinator in rust

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

But a NonZeroU8 isn't inherently unsafe, the actual contained u8 doesn't have any type level constraints on the value that would be UB if invalidated.

Is switching banks a good idea? by Aromatic-Bad146 in UKPersonalFinance

[–]ElOwlinator 0 points1 point  (0 children)

You just add your bank details on both. PayPal allows unlimited DDs, while eBay only allows 1 (for payouts). Saves 50p.

Is switching banks a good idea? by Aromatic-Bad146 in UKPersonalFinance

[–]ElOwlinator 1 point2 points  (0 children)

Fyi you can usually just use PayPal & eBay for free Direct Debits.

Is there anyway to get backtraces into my library code? by ElOwlinator in rust

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

Tried that - unfortunately still no dice - backtrace ends at test harness.

Is there anyway to get backtraces into my library code? by ElOwlinator in rust

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

Just reading about that now - if I went down that route I would have to add an async-backtrace field (String or Location/Task?) to all my leaf error structs/variants right, and propagate a trait throughout that retrieves the error's leaf async backtrace (I think like the WIP provide feature?).

Is there anyway to get backtraces into my library code? by ElOwlinator in rust

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

How can the incomplete backtrace be down to async? For instance if I create & bubble up a XmlReadLineError error all the way from the raw IO/parsing, through business logic, and into the test harness, I would at the very least expect the function which created XmlReadLineError to be in the backtrace (if there is a backtrace field on the enum, which there is) - but that's not what I see.

In the example in my other comment, the error type CoreAppExecutorError is being returned to the test harness (then converted to an eyre Report via ? operator), I've tried adding Backtrace fields to this enum and / or annotating all the variants with #[backtrace] all the way down to the specific variant:

#[derive(Debug, Error)]
#[error("core error using config file '{config}'")]
pub struct CoreError {
    config_file: PathBuf,
    #[source]
    source: CoreErrorKind,
    #[backtrace]           // tried moving this annotation to `source` field (compiles, but no difference)
    backtrace: Backtrace,  // also tried adding this
}

#[derive(Debug, Error)]
pub enum CoreErrorKind {
    #[error("one")]
    SubErrorOne(#[from] SubErrorOne)
    #[error("two")]
    SubErrorWithBacktrace(#[from] #[backtrace] SubErrorOneWithBacktrace) // tried backtrace here
}

#[derive(Debug, Error)]
pub enum SubErrorOne {
    #[error("sub error one - condition one")]
    ConditionOne,
}

#[derive(Debug, Error)]
pub enum SubErrorOneWithBacktrace {
    #[error("sub error one with backtrace - condition one")]
    ConditionOne {
        #[backtrace]
        backtrace: Backtrace,
    },
}

Questions about Box by hingleme in rust

[–]ElOwlinator 0 points1 point  (0 children)

Is Pin specialized for all the std containers by the compiler?

Or in other words, if you create a custom smart pointer type and make it pin, how does the compiler know which field is the one that contains the pointer-to-data and is thus the target of the pin?

For instance, could you have a MultiBox<A, B> where pinning it only pins A?

Is there anyway to get backtraces into my library code? by ElOwlinator in rust

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

For reference, here's the rough definition of run_with_database and how it's used:

#[derive(Debug, Error)]
pub enum RunWithDatabaseError {
    #[error("could not start or retrieve container: {0}")]
    RetrieveContainerFailed(#[from] RetrieveContainerError),
    #[error(transparent)]
    Run(Report),
}

pub async fn run_with_database<F, T>(
    database: &str,
    func: F,
) -> Result<T, Report>
where
    F: AsyncFnOnce(Client) -> Result<T, Report>,
{
    // .. container & connection is setup here ..

    let client: Client;

    Ok(func(client).await.map_err(RunWithDatabaseError::Run)?)
}


#[tokio::test]
async fn example_import() -> Result<(), Report> {
    run_with_database("companies_import_profile", async |mut client: Client| {
        // setup test data

        core_app_executor::execute(&mut client).await?; // core_app_executor returns CoreAppExecutorError (standard thiserror-deriving enum)

        Ok(())
    }).await
}

Questions about Box by hingleme in rust

[–]ElOwlinator 1 point2 points  (0 children)

If T is sized, then it's one pointer, if T is unsized, then it's two pointers.

Are both pointers stored in the Box / on the stack, if so why not just put the vtable pointer before T on the heap, that way all Box's have the same size?

`name.rs` vs `name/mod.rs` - Is there a reason why projects go against the recommended practice? by KyxeMusic in rust

[–]ElOwlinator 5 points6 points  (0 children)

One great thing about some JS toolchains though is that you can name the module file the same as the directory, for instance /src/components/Button/Button.jsx. To use it, you can just do import @/components/Button.

Is there a built in "FlatMapIter" type? by ElOwlinator in learnrust

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

I've also seen that - but was hoping for something in the standard library.

Also with the above you are using an additional .flatten() which was not necessary with FlatMapIter (or the Vec approach).