pagerduty-rs
pagerduty-rs copied to clipboard
Generic parameters and Into<Cow>
Hi, just stumbled upon this from your blog post :) Just a minor note, if you want things to make as nice as possible, you may want to not restrict the string type to be the same when a function accepts multiple parameters:
pub fn image<S>(src: S, href: Option<S>, alt: Option<S>) -> Context<'a>
where S: Into<Cow<'a, str>>
should probably be
pub fn image<S1, S2, S3>(src: S1, href: Option<S2>, alt: Option<S3>) -> Context<'a>
where S1: Into<Cow<'a, str>>, S2: Into<Cow<'a, str>>, S3: Into<Cow<'a, str>>
(otherwise you're either only accepting all &str, or all String, but can't mix them)
The signature looks fairly ugly though, gotta give it that :)
Interesting! I had not considered that the simple version will enforce a single type. Thanks for sharing. I'm going to leave this open until I can get around to fixing it. Sure is ugly, though :grin:
Np! Btw, note that the lifetimes are also constrained to a single 'a here, so the structs/methods would have to use <'a, 'b, 'c, 'd, 'e> etc in order not to be too restrictive? 😄
Couldn't we get away with introducing additional lifetimes on a per method basis and enforce 'b: 'a where 'a is the lifetime of the struct?
Hmm I'm not sure that would work but would be interested if you find out :)