--- Day changed Thu Nov 08 2018 00:04 < dpc[m]> stevenroose (IRC): Woohoo. I should have some time to look today evening PST. 00:05 < dpc[m]> So is it a consensus that we take your version and go with that (fine with me, just want to make sure). 00:07 < dpc[m]> For optional arguments I was planing to make a `do_rpc_with_optionals(&self, args: &[Option], defaults: &[serde_json::value::Value])` and just do the trimming and substitutions in there. 00:08 < dpc[m]> It shouldn't even need allocations, since triming this slice should be in place `&[..index]` 00:10 < dpc[m]> And you can deduce where the optionals start in the `args` by the lenght of `defaults`. 00:17 < stevenroose> dpc[m]: look at my comment if you can 00:17 < stevenroose> So I removed the need for the macro, have two response paths: into_json and into_struct (not very happy about latter name, but it's basically parse hex and rust-bitcoin deserialize) 00:19 < stevenroose> And then for optionals I have these arg and oarg wrappers. self.call does take a Vec instead of a slice, however, because of the enum that I use in the middle. 00:20 < dpc[m]> stevenroose (IRC): Yeah, I'm looking at it. :) 00:20 < dpc[m]> I like it better because there is no macros. :D 00:21 < stevenroose> Oh, it it would take not a &[serde::Value] but something like a &[Into You understand the issue, right? You want to keep the info on whether or not the value was put by a default value or not, somehow. 00:22 < dpc[m]> stevenroose (IRC): You can't have $[Trait]. 00:22 < dpc[m]> `do_rpc_with_optionals(&self, args: &[Option], defaults: &[serde_json::value::Value])` 00:22 < dpc[m]> Doesn't this fix everything? 00:23 < dpc[m]> You take all args and build `&[arg1.map(into_value), arg1.map(into_value), ..]` 00:24 < stevenroose> hmm, like self.call("cmd", &[arg1.into()], &[optional.map(into_value)], &[default1.into()]) (like 2 slices: normal args, optional args, default for optionals)? 00:25 < stevenroose> I guess that would work, yes 00:25 < stevenroose> Minor nit is that default values are then more distant from the argument names, but that's fine I guess. 00:25 < stevenroose> let me try that 00:27 < dpc[m]> I guess one vector allocation will be needed anyway, when rewritting `None`s into the right value. Oh well. 00:29 < stevenroose> Couldn't that be written in a new slice? 00:30 < dpc[m]> Well, yes. But that slice has to come from somewhere - new allocated vector or something. 00:30 < stevenroose> hmm, does that evne make sense? making a new slice of some length? that's an array, isn't it 00:31 < dpc[m]> I'm not sure if I understand. :) 00:31 < stevenroose> nvm 00:31 < dpc[m]> Let's not worry about allocations are right now. After we have the API, we can think about optimizations. 00:31 < stevenroose> brainfart :p 00:32 < stevenroose> also in my index, rust-jsonrpc::build_request still takes a vector, not a slice, so I need to allocate it anyway 00:33 < dpc[m]> Yeah, but if this lands: https://github.com/apoelstra/rust-jsonrpc/pull/19/files#diff-b4aea3e418ccdb71239b96952d9cddb6R50 it won't be neccessary. 00:34 < dpc[m]> Got to leave soon. Please keep me in loop. 00:43 < stevenroose> dpc[m]: I'm gonna follow your advice and not care about allocations. I can't seem to make it work with slices :/ 00:56 < stevenroose> dpc[m]: If you're still here: the optional.map(into_value) is a little cumbersome since serde_json::to_value returns a Result 00:56 < dpc[m]> One trick is that we don't have to even use `args: &[Option]`, we can just go with `args: &[serde_json::value::Value]` and replace `None`s with `serde_json::value::Value::None`. 00:56 < dpc[m]> So if we pass `args: &[serde_json::value::Value]` stuff can be replaced in place. Anyway. 00:57 < dpc[m]> I guess we will just use a helper function. that reverts it, so we can `?` on it. 00:57 < dpc[m]> Actually ... Can't we just `unwrap` there? The types there can't fail to serialize to Json. 00:58 < dpc[m]> Leaving now. Good luck and let's stay in touch. :D 00:59 < stevenroose> dpc[m]: you're saying we verify for all our types that the serializer can't fail? 00:59 < stevenroose> adding a ? seems safer somehow, though :p and yeah I guess stdlib should have something that can Option to Result