-
Notifications
You must be signed in to change notification settings - Fork 41
Implement Encode
for sequences of string-like types
#377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Implement Encode
for sequences of string-like types
#377
Conversation
I'm not sure what you're trying to accomplish with this, and notably types like |
This was simply meant to be something I could link to as I asked a followup question to your comment on #314. I didn't have time to finish it earlier, hence the draft status and no question posted yet. In retrospect I could just as easily have linked to a commit, so I apologize for the noise of an additional PR.
My question would have been: I'm not quite sure I understand what you mean by this. Something like this (PR)? "Encoding a message this way is actually valid" --> a trait for types that encode into an RFC4251 string? (Judging by your answer I'm going to guess this was not quite what you had in mind.) |
Oh sorry, I was missing the context. My bad. Maybe call it something like |
Happy to rename it. What blanket impl would that be? There's already these two: impl<T: EncodesLikeString> Encode for [T] { ... }
impl<T: EncodesLikeString> Encode for Vec<T> { ... } With some more boilerplate it can be expanded to cover all kinds of combinations of references, slices and owned types too, like |
EncodesLikeString
for types that encode like SSH stringsEncode
for sequences of string-like types
I was referring to this one: #314 (comment) You don't appear to currently have a generic impl for |
Only the one bounded by |
Yeah, that seems problematic |
With this change, various types like `&[&str]`, `Vec<&String>, &[Vec<u8>`, etc. are now `Encode` by default, and encode as an RFC4251 string of the encoded entries. Custom types can opt into this by implementing the marker trait `Rfc4251String`. Implementation note: This would be more general and cover more types if we could blanket `impl<T: Encode> Encode for &T`, as this would cover any level of references in the trait bound for the `Rfc4251String` blanket implenentation. However, this would collide with the `Label` trait, so instead this adds explicit impls for the immediate types that we implement `Encode` for.
e32c9d5
to
c242dab
Compare
I've tried to clean it up a bit and make it as general as I can without stepping on the compiler's toes. Feel free to review if you think it adds anything, or just close it if it confuses more than it helps. |
This is in turn used to implementIntroduce a marker trait for types that encode into ssh-strings, and implementEncode
for slices of string-like types.Encode
for various kinds of sequences of such types. E.g. implementEncode
forVec<String>
,&[&str]
, etc. Downstream users could implement the marker trait for their own types and get the same behavior for slices of their own types.Closes #314.