Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::Deref;
- struct Big<'a> {
- option: BigOption,
- small: Small<&'a SmallOption>,
- }
- struct Small<T: Deref<Target = SmallOption>> {
- option: T,
- }
- struct BigOption {
- a: u32,
- small_option: SmallOption,
- }
- struct SmallOption {
- b: u32,
- }
- impl<T: Deref<Target = SmallOption>> Small<T> {
- fn new(option: T) -> Self {
- Self {
- option,
- }
- }
- }
- impl<'a> Big<'a> {
- fn new(option: BigOption) -> Self {
- let small = Small::new(&option.small_option);
- Self { option, small }
- }
- }
- fn main() {
- let big_option = BigOption {
- a: 123,
- small_option: SmallOption {
- b: 456,
- }
- };
- Big::new(big_option);
- }
Advertisement
Add Comment
Please, Sign In to add comment