From e409df3861f48de44d0e37277ce007e348a7a0dc Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 3 Jul 2020 13:07:35 +0200 Subject: 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. --- pkgs/profpatsch/netencode/record-get.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'pkgs/profpatsch/netencode/record-get.rs') 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())) + } } } } -- cgit 1.4.1