diff options
author | Profpatsch <mail@profpatsch.de> | 2020-07-03 13:07:35 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2020-07-06 20:13:42 +0200 |
commit | e409df3861f48de44d0e37277ce007e348a7a0dc (patch) | |
tree | 6e70ad4a7889c2fdc9b9ea6a2b0af51accc97d51 /pkgs/profpatsch/netencode/record-get.rs | |
parent | 124daced37aaab646c83b75711bf744c1d295a8b (diff) |
pkgs/profpatsch/netencode: Encode into U instead of T
This is an experiment about whether we can get away with using the non-recursive version by default. The U::Record variant uses a Vec instead of a HashMap by default, to make encoding from lists easier, and keep the ordering as given.
Diffstat (limited to 'pkgs/profpatsch/netencode/record-get.rs')
-rw-r--r-- | pkgs/profpatsch/netencode/record-get.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/pkgs/profpatsch/netencode/record-get.rs b/pkgs/profpatsch/netencode/record-get.rs index bf4db3dd..c823249d 100644 --- a/pkgs/profpatsch/netencode/record-get.rs +++ b/pkgs/profpatsch/netencode/record-get.rs @@ -6,7 +6,7 @@ use std::io::Read; use std::ffi::{CString, OsStr}; use std::os::unix::ffi::{OsStringExt, OsStrExt}; use el_semicolon::{el_semicolon, Arg}; -use netencode::{U}; +use netencode::{U, encode}; use netencode::parse::{u_u}; fn main() { @@ -30,9 +30,16 @@ fn main() { // only set if it appears in the block of values. // If the block is empty, don’t filter. if vars.is_empty() || vars.contains(&key.as_bytes()) { + // TODO this is a super unprincipled special casing of some values + // We should have a way of destructuring stuff match *val { U::Binary(b) => std::env::set_var(key, OsStr::from_bytes(b)), - _ => panic!("the value of {:?} was not a binary value!", key) + U::Text(t) => std::env::set_var(key, OsStr::from_bytes(t)), + u => { + let mut c = std::io::Cursor::new(vec![]); + encode(&mut c, u); + std::env::set_var(key, OsStr::from_bytes(&c.into_inner())) + } } } } |