8000 References support · Issue #239 · cksac/fake-rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

References support #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xamgore opened this issue May 18, 2025 · 1 comment
Open

References support #239

xamgore opened this issue May 18, 2025 · 1 comment

Comments

@xamgore
Copy link
xamgore commented May 18, 2025

I have a tree like structure: Warehouse <- Zone<'p>.

#[derive(Debug, Clone, Dummy)]
pub struct WarehouseTopology {
    pub label: String,
}

#[derive(Debug, Clone, Dummy)]
pub struct ZoneTopology<'p> {
    pub _whs: &'p WarehouseTopology,
    pub label: String,
}

Why can't I derive Dummy for it?

Image
@xamgore
Copy link
Author
xamgore commented May 18, 2025

Well, I was able to split the struct onto a fakeable part and non-fakeable (keeping a reference).

#[derive(Serialize)]
pub struct ZoneTopology {
    _whs: &'p Parent,
   #[serde(flatten)]
   zone: Zone,
}

#[derive(Serialize, Dummy)]
pub struct Zone {
  label: String,
}

But macros could return something that accepts an argument — the reference to Parent.

let whs = Warehouse { .. };
let zone = faker.fake(&whs);

@xamgore xamgore changed the title Lifetimes support References support May 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0