```bash
pub mod e1 {
    struct SomeState;
    fn new_state(_: u32) -> SomeState {
        SomeState
    }

    struct StorageEngine {
        page: u32,
        state: Option<SomeState>,
        c: u32,
    }

    impl StorageEngine {
        fn assign_next_page(&mut self) -> u32 {
            let page = self.page;
            self.page += 1;
            page
        }

        // fn problem(&mut self) -> (&mut u32, &mut u32, &mut SomeState) {
        //     let state = self.state.get_or_insert_with(|| {
        //         let x = self.assign_next_page();
        //         new_state(x)
        //     });
        //     (&mut self.c, &mut self.page, state)
        // }
    }
}
```

```bash
pub mod e2 {
    struct Slices;

    impl Slices {
        fn some_code(&mut self) {}
    }

    struct Segment;
    fn some_f2(_: &Segment) -> u64 {
        0
    }

    pub struct FileBuilder {
        segments: Vec<Segment>,
        slices: Slices,
    }

    impl FileBuilder {
        // fn problem(&mut self) {
        //     for (i, s) in self.segments.iter().enumerate() {
        //         self.append_slice(some_f2(s), i);
        //     }
        // }

        fn append_slice(&mut self, _: u64, _: usize) {
            self.slices.some_code();
        }
    }
}
```

```bash
pub mod e3 {
    struct Segment {
        rel_media_range_90k: i32,
    }

    impl Segment {
        fn media(&self) -> i32 {
            0
        }
    }

    pub struct FileBuilder {
        segments: Vec<Segment>,
        buf: Vec<u8>,
    }

    impl FileBuilder {
        // fn problem(&mut self) {
        //     for s in &self.segments {
        //         let mr = &s.rel_media_range_90k;
        //         let media_off = s.media();
        //         self.append_u32(Self::some_f5(mr, media_off));
        //     }
        //     Self::some_code4(&mut self.buf[0..3]);
        // }

        fn some_f5(_: &i32, _: i32) -> u32 {
            0
        }

        fn some_code4(_: &mut [u8]) {}

        fn some_code3(_: &mut Vec<u8>, _: u32) {}

        fn append_u32(&mut self, v: u32) {
            Self::some_code3(&mut self.buf, v);
        }
    }
}
```

```bash
pub mod e4 {
    struct SigStore;
    struct DiagnosticStore;
    struct ItemStore;
    struct Stores<'a, 'b, 'c> {
        pub items: &'c mut ItemStore,
        pub sigs: &'a mut SigStore,
        pub diags: &'b mut DiagnosticStore,
    }
    struct StructDef {
        fields: Vec<StructDefField>,
    }
    struct StructDefField;

    fn some_f(a: &SigStore, b: usize) -> &StructDef {
        todo!()
    }

    fn some_f4(a: &StructDefField) -> &NameResolvedType {
        todo!()
    }

    enum NameResolvedType {
        SimpleCustom { id: usize },
        Array(Box<NameResolvedType>, usize),
    }

    // fn problem(stores: &mut Stores) {
    //     let struct_def = some_f(&stores.sigs, 0);
    //     for field in &struct_def.fields {
    //         check_invalid_cyclic_refs_in_field_kind(stores, some_f4(field));
    //     }
    // }

    fn some_code2(a: &ItemStore, c: usize, h: &mut DiagnosticStore) {}

    fn check_invalid_cyclic_refs_in_field_kind(stores: &mut Stores, field_kind: &NameResolvedType) {
        match field_kind {
            NameResolvedType::SimpleCustom { id, .. } => {
                some_code2(&stores.items, *id, stores.diags);
            }
            NameResolvedType::Array(id, _) => {
                let mut inner_array_id = id;

                while let NameResolvedType::Array(inner, _) = &**inner_array_id {
                    inner_array_id = inner;
                }

                // We've now reached the innermost type of the array.
                check_invalid_cyclic_refs_in_field_kind(stores, inner_array_id);
            }
            _ => {}
        }
    }
}
```

```bash
pub mod e5 {
    pub struct FragmentBuilder;
    impl FragmentBuilder {
        pub(crate) fn some_f(block0_hash: &usize, linear_fees: &Block0Configuration) {
            todo!()
        }
    }
    pub struct Block0Configuration;
    use std::collections::HashMap;

    pub struct Wallet;

    impl Wallet {
        pub fn confirm_transaction(&mut self) {
            todo!()
        }
    }
    pub struct CommitteeMembersManager;

    #[derive(Clone)]
    pub struct VotePlanManager;

    pub struct VoteRoundGenerator {
        block0: Block0Configuration,
        block0_hash: usize,
        committee_wallets: HashMap<usize, Wallet>,
        voteplan_managers: HashMap<usize, VotePlanManager>,
        committee_manager: CommitteeMembersManager,
    }

    impl VoteRoundGenerator {
        // pub fn problem(&mut self) {
        //     self.voteplan_managers = self
        //         .voteplan_managers
        //         .iter()
        //         .map(|(id, manager)| {
        //             let manager = Self::some_f2(&self.committee_manager, &self.block0, manager);
        //             self.prepare_tally_fragments(&manager);
        //             (id.clone(), manager)
        //         })
        //         .collect::<HashMap<_, _>>();
        // }

        fn some_f2(
            a: &CommitteeMembersManager,
            b: &Block0Configuration,
            c: &VotePlanManager,
        ) -> VotePlanManager {
            todo!()
        }

        fn prepare_tally_fragments(&mut self, voteplan: &VotePlanManager) {
            let committee_member = self.committee_wallets.values_mut().next().unwrap();
            FragmentBuilder::some_f(&self.block0_hash, &self.block0);
            committee_member.confirm_transaction();
        }
    }
}
```

```bash
pub mod e6 {
    pub struct Database {
        pub models: Vec<Model>,
    }
    pub struct Model {
        pub objects: Vec<Object>,
    }

    pub struct Object {
        pub matrix: f64,
    }

    pub struct Viewer {
        db: Database,
        model_id: usize,
        object_mats: Vec<f64>,
    }

    impl Viewer {
        // fn problem(&mut self) {
        //     self.object_mats.clear();
        //     for obj in &self.cur_model().objects {
        //         self.object_mats.push(obj.matrix);
        //     }
        // }

        fn cur_model<'a>(&'a self) -> &'a Model {
            &self.db.models[self.model_id]
        }
    }
}
```

```bash
pub mod e7 {
    pub struct Database {
        pub animations: Vec<Animation>,
    }

    pub struct Connection {
        pub models: Vec<ModelConnection>,
    }
    pub struct ModelConnection {
        pub animations: Vec<usize>,
    }

    pub struct Animation {
        pub objects_curves: Vec<TRSCurves>,
    }

    pub struct TRSCurves;

    impl TRSCurves {
        pub fn sample_at(&self) -> f64 {
            todo!()
        }
    }

    pub struct Viewer {
        db: Database,
        conn: Connection,
        model_id: usize,
        object_mats: Vec<f64>,
    }

    struct AnimState {
        connection_idx: Option<usize>,
        frame: u16,
    }

    impl Viewer {
        // fn problem(&mut self) {
        //     if let Some(anim) = self.cur_animation() {
        //         for i in 0..self.object_mats.len() {
        //             self.object_mats[i] = anim.objects_curves[i].sample_at();
        //         }
        //     }
        // }

        fn cur_animation<'a>(&'a self) -> Option<&'a Animation> {
            Some(&self.db.animations[self.animation_id()?])
        }

        fn animation_id(&self) -> Option<usize> {
            Some(self.conn.models[self.model_id].animations[0])
        }
    }
}
```

```bash
mod e8 {
    pub struct Database {
        pub models: Vec<Model>,
        pub mat_anims: Vec<MaterialAnimation>,
    }

    pub struct Connection {
        pub models: Vec<ModelConnection>,
    }

    pub struct MatAnimConnection {
        pub mat_anim_id: usize,
    }

    pub struct ModelConnection {
        pub mat_anims: Vec<MatAnimConnection>,
    }

    pub struct Model {
        pub materials: Vec<Material>,
    }

    pub struct Material;

    pub struct MaterialAnimation {
        pub tracks: Vec<MaterialTrack>,
    }

    pub struct MaterialTrack {}

    impl MaterialTrack {
        pub fn eval_uv_mat(&self, _: u16) -> f64 {
            todo!()
        }
    }

    pub struct Viewer {
        db: Database,
        conn: Connection,
        model_id: usize,
        uv_mats: Vec<f64>,

        mat_anim_state: AnimState,
    }

    struct AnimState {
        connection_idx: Option<usize>,
        frame: u16,
    }

    impl Viewer {
        // fn problem(&mut self) {
        //     if let Some(mat_anim) = self.cur_mat_anim() {
        //         for track in &mat_anim.tracks {
        //             for (i, _) in self.cur_model().materials.iter().enumerate() {
        //                 self.uv_mats[i] = track.eval_uv_mat(self.mat_anim_state.frame);
        //             }
        //         }
        //     }
        // }

        fn cur_model<'a>(&'a self) -> &'a Model {
            &self.db.models[self.model_id]
        }

        fn cur_mat_anim<'a>(&'a self) -> Option<&'a MaterialAnimation> {
            Some(&self.db.mat_anims[self.mat_anim_id()?])
        }

        fn mat_anim_id(&self) -> Option<usize> {
            let idx = self.mat_anim_state.connection_idx?;
            Some(self.conn.models[self.model_id].mat_anims[idx].mat_anim_id)
        }
    }
}
```

```bash
/// For context about async:
///
/// async function still can borrow, and the borrow will be until the result is awaited.
/// before awaited, it is being borrowed. After awaited the borrow ends.
///
/// For the case where async fns return a borrow, the input borrow is active before awaiting.
/// After awaiting it acts like a regular function (input borrow is active while returned borrow is alive)
mod e9 {
    use std::marker::PhantomData;

    struct WriteHalf<'a>(PhantomData<&'a ()>);

    #[derive(Debug, Clone, Default)]
    struct Frontier;

    async fn send_message<'a, W>(stream: &mut W) {}

    fn some_code(a: &mut Frontier) {}

    #[derive(Debug)]
    struct ConnectionState {
        remote_frontier: Frontier,
    }
    struct TcpStream;

    impl TcpStream {
        pub fn split<'a>(&'a mut self) -> (ReadHalf<'a>, WriteHalf<'a>) {
            todo!()
        }
    }

    struct BufReader<T>(PhantomData<T>);
    impl<T> BufReader<T> {
        pub async fn next_line(&mut self) -> Option<String> {
            todo!()
        }
    }
    impl<T> BufReader<T> {
        pub fn some_code(x: T) -> Self {
            todo!()
        }
    }
    struct ReadHalf<'a>(PhantomData<&'a ()>);

    pub struct Protocol<'socket> {
        socket: &'socket mut TcpStream,
        state: Option<ConnectionState>,
    }

    impl<'socket> Protocol<'socket> {
        async fn handle_message(&mut self, _: String, writer: &mut WriteHalf<'_>) {
            let state = self.state.as_mut().unwrap();
            some_code(&mut state.remote_frontier);
            send_message(writer).await;
        }

        pub async fn problem(&mut self) {
            // let (reader, mut writer) = self.socket.split();
            // let mut reader = BufReader::some_code(reader);
            // loop {
            //     let line = reader.next_line();
            //     if let Some(line) = line.await {
            //         self.handle_message(line, &mut writer).await;
            //     } else {
            //         break;
            //     }
            // }
        }
    }
}
```