Last active
May 9, 2022 03:54
-
-
Save nanpuyue/86c77219e4d0412502781fc193e06127 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// date: 2022-05-09 | |
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
// author: nanpuyue <[email protected]> https://blog.nanpuyue.com | |
use std::mem::take; | |
fn push(buf: &mut &mut [u8], value: u8) { | |
buf[0] = value; | |
*buf = &mut take(buf)[1..]; | |
} | |
fn main() { | |
let mut buf = [0; 8]; | |
let mut cur = &mut buf[..]; | |
println!("cur: {cur:p}, {cur:?}"); | |
for i in 1..=8 { | |
push(&mut cur, i); | |
println!("cur: {cur:p}, {cur:?}"); | |
} | |
println!("buf: {buf:?}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment