Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Last active May 9, 2022 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 <nanpuyue@gmail.com> 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