Rust idiomatic solution
\nstruct OrderedStream {\n    arr: Vec<Option<String>>,\n    ptr: usize\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need 
```\nstruct OrderedStream {\n    arr: Vec<Option<String>>,\n    ptr: usize\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl OrderedStream {\n\n    fn new(n: i32) -> Self {\n        Self {\n            arr: vec![None; n as usize],\n            ptr: 0\n        }\n    }\n    \n    fn insert(&mut self, id_key: i32, value: String) -> Vec<String> {\n        let id_key = id_key as usize - 1;\n        self.arr[id_key] = Some(value);\n        \n        if id_key > self.ptr {\n            return vec![];\n        }\n        \n        while let Some(Some(_)) = self.arr.get(self.ptr) {\n            self.ptr += 1;\n        }\n        self.arr[id_key..self.ptr].iter_mut().map(|opt| opt.take().unwrap()).collect()\n    }\n}\n```
['Rust']