Skip to content
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

Converting between Contexts #1308

Open
axos88 opened this issue Jan 20, 2025 · 1 comment
Open

Converting between Contexts #1308

axos88 opened this issue Jan 20, 2025 · 1 comment

Comments

@axos88
Copy link

axos88 commented Jan 20, 2025

Having a

  struct Context {
    a: u32,
    b: bool,
    c: String
  }

  struct SubContext1 {
    a: u32,
    b: bool
  }

  struct SubContext2 {
    a: u32,
    c: String
  }

How can the FromContext implementations be written? Seems like they take and return a reference, and there doesn't seem to be a way to satisfy the borrow checker.

Maybe FromContext should take, or have the ability to take a [clonable] context and produce an owned value?

@axos88
Copy link
Author

axos88 commented Jan 20, 2025

Something like:

pub trait FromContext<'a, T> {
    fn from(v: &'a T) -> Self;
}

with a default implementation of

impl<'a, T> FromContext<'a, T> for &'a T {
    fn from(v: &'a T) -> Self {
        v
    }
}

perhaps?

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