Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Last active May 9, 2022 03:54
Show Gist options
  • Save nanpuyue/86c77219e4d0412502781fc193e06127 to your computer and use it in GitHub Desktop.
Save nanpuyue/86c77219e4d0412502781fc193e06127 to your computer and use it in GitHub Desktop.
// 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