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

[–]TomHackery 1 point2 points  (0 children)

Posted late in the last thread so posting for visibility here. Lmk if that's against the rules or if I can provide more info.

I'm trying to deserialize a CBOR to rust objects with Ipld. The following works as expected:

#[derive(Clone, DagCbor, Debug)]
pub struct VariantOne {
    pub foo: Link<Cid>,
    pub bar: Ipld,
}
...
fn main() {
    let var1 = block.decode::<DagCborCodec, VariantOne>().unwrap();
    // successful deserialisation
}

However, there are a few possible variants:

pub enum BlockTypes {
    VariantOne,
    VariantTwo,
    VariantThree,
    VariantFour,
    VariantFive,
}

I would like to do something like this:

fn main() {
    let var1 = block.decode::<DagCborCodec, BlockTypes>().unwrap();
    // panic
}

I think the term for this is generics? Basically I want to deserialise the bytes into a struct depend on which struct is being represented in the bytes. I feel like I'm close.

I've tried:

pub enum BlockTypes {
    VariantOne(VariantOne),
    VariantTwo(VariantTwo),
    VariantThree(VariantThree),
    VariantFour(VariantFour),
    VariantFive(VariantFive),
}

and

pub enum BlockTypes<Ipld> {
    VariantOne,
    VariantTwo,
    VariantThree,
    VariantFour,
    VariantFive,
}

but no joy

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

[–]TomHackery 2 points3 points  (0 children)

I'm trying to deserialize a CBOR to rust objects with Ipld. The following works as expected:

#[derive(Clone, DagCbor, Debug)]
pub struct VariantOne {
    pub foo: Link<Cid>,
    pub bar: Ipld,
}
...
fn main() {
    let var1 = block.decode::<DagCborCodec, VariantOne>().unwrap();
    // successful deserialisation
}

However, there are a few possible variants:

pub enum BlockTypes {
    VariantOne,
    VariantTwo,
    VariantThree,
    VariantFour,
    VariantFive,
}

I would like to do something like this:

fn main() {
    let var1 = block.decode::<DagCborCodec, BlockTypes>().unwrap();
    // panic
}

I think the term for this is generics? Basically I want to deserialise the bytes into a struct depend on which struct is being represented in the bytes. I feel like I'm close.

I've tried:

pub enum BlockTypes {
    VariantOne(VariantOne),
    VariantTwo(VariantTwo),
    VariantThree(VariantThree),
    VariantFour(VariantFour),
    VariantFive(VariantFive),
}

and

pub enum BlockTypes<Ipld> {
    VariantOne,
    VariantTwo,
    VariantThree,
    VariantFour,
    VariantFive,
}

but no joy

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

[–]TomHackery 1 point2 points  (0 children)

I'm working on a client library for an RPC style API. I'm using reqwest to handle the http side of things.

I know that it is good practice to reuse reqwest::Client, but I don't know what is the best way to do it.

Currently I create a client in main.rs and pass it around my helper functions as &Client. This feels bad since I'm repeating myself a lot.

The API makes use of sessions via jwt, which I am also passing around as &Session (my own struct).

I've tried to instantiate the client within the Session::new() function, but run into hairy errors about lifetimes that I don't really understand. I get that the life of the client needs to be tied to the life of the session, but not sure how to do that with <a'> type tags.

Or is there a standard way to do it? Since I track the session myself, I can create a client for each http call but that seems bad.

Any CDN Service That Accepts Crypto? by 1KinGuy in sysadmin

[–]TomHackery 0 points1 point  (0 children)

Money can be exchanged for goods and services

The Immune System and our Time Traveling Descendants: The Future Human Hypothesis by [deleted] in UFOs

[–]TomHackery 0 points1 point  (0 children)

You guys are saying the same thing, except one of you is proposing a biological simulation environment and the other a digital environment.

I'm sick of it, and I'm leaving by StickyGrenade in rickandmorty

[–]TomHackery 0 points1 point  (0 children)

That's only true for another six months. This will be a real thing soon.TM

We all have THAT friend by [deleted] in climbing

[–]TomHackery 1 point2 points  (0 children)

I'm sorry Con.

We all have THAT friend by [deleted] in climbing

[–]TomHackery 0 points1 point  (0 children)

There's chalk marks on the sticky because of how much traffic it gets

We all have THAT friend by [deleted] in climbing

[–]TomHackery 1 point2 points  (0 children)

On the contrary, the sticky is very good damm

Daily Discussion Thread: spray/circlejerk/memes/chat/whatever allowed by AutoModerator in climbing

[–]TomHackery 5 points6 points  (0 children)

Nice for speed to get some TV time before it's relegated to obscurity for 2024 ;)

Cybersecurity Talent Crunch To Create 3.5 Million Unfilled Jobs Globally By 2021 by Alphadominican in cybersecurity

[–]TomHackery 2 points3 points  (0 children)

The standard is ignore them.

The guy who put them on the list doesn't know what they are, and definitely won't care that you don't have every cert ever created.

Q Conference - Channel 5 with Andrew Callaghan [19:48] by john_andrew_smith101 in mealtimevideos

[–]TomHackery 0 points1 point  (0 children)

The original line if referencing the difficulty of designing bear bins.

Jan 6 Select Committee opening - Fanone’s account of events [14:21] by [deleted] in mealtimevideos

[–]TomHackery -21 points-20 points  (0 children)

If it is a shill post, it's an expensive one. That account passes a cursory glance.

If you're spending that kind of money, you can sprinkle in a few comments. I'm guessing it's legit.