Introduce extension trait for attaching#675
Conversation
This saves some steps for humility as a library
| } | ||
|
|
||
| impl HubrisAttach for humility::hubris::HubrisArchive { | ||
| fn attach(&self, probe: &str) -> Result<Box<dyn Core>> { |
There was a problem hiding this comment.
Hmmm, should this be called attach_to_chip or attach_probe to be less ambiguous (especially if we're going to add more methods in the future)?
There was a problem hiding this comment.
I'll go with attach_to_chip to match
There was a problem hiding this comment.
Sorry for being pedantic, but now that you've updated it I've convinced myself that attach_probe is the Right Name:
- The single
&strargument is a probe name, not a chip name - It returns a boxed-up
ProbeCore
jamesmunns
left a comment
There was a problem hiding this comment.
I have a personal bias against "extension traits", mostly because they don't show up well in docs and can be a little tedious to use.
That being said: I don't totally understand the intended use, and if the intent is that 3rd party (at least "not humility") libraries are going to implement and use it, rather than humility implementing this interface for external libraries, I probably wouldn't call this an "extension trait" anyway!
It might be worth documenting when and why folks would want to impl this trait on their types, and what it does/doesn't get them?
| } | ||
|
|
||
| /// Extension trait to make it easier for libraries to attach | ||
| /// to chips. It is encourageed to extend this trait as |
There was a problem hiding this comment.
| /// to chips. It is encourageed to extend this trait as | |
| /// to chips. It is encouraged to extend this trait as |
| /// to chips. It is encourageed to extend this trait as | ||
| /// needed to make developer's lives easier. | ||
| pub trait HubrisAttach { | ||
| fn attach_to_chip(&self, probe: &str) -> Result<Box<dyn Core>>; |
There was a problem hiding this comment.
Maybe document what this is supposed to do and when this should/shouldn't fail?
| } | ||
|
|
||
| impl HubrisAttach for humility::hubris::HubrisArchive { | ||
| fn attach_to_chip(&self, probe: &str) -> Result<Box<dyn Core>> { |
There was a problem hiding this comment.
Just a check, do we want this to be Box<dyn Core> instead of being an assoc type? (if we're already using it as dyn everywhere in existing code, the answer is probably "yes")
Perf wise it probably doesn't matter, but just checking because sometimes dyn Trait is "a land of contrasts", as Eliza would say.
There was a problem hiding this comment.
yeah we return dyn Core everywhere (see the other attach functions in https://github.com/oxidecomputer/humility/blob/8f0fb59e4c0d7453f1382a1700915e6c59cfe07e/humility-probes-core/src/lib.rs)
Maybe I'm using the term "extension trait" incorrectly. This isn't intended to be implemented by anyone and is more a hack to be able to have another Which is a bit ugly. My thought was that it would be much more natural to just do I'm not super attached to the trait (pun not intended) so maybe a static function would be cleaner? |
|
Looking at all this code makes me want to rework attaching because it's not well documented but I am trying to avoid finding yet another Yak to shave (there are so many in humility) |
This saves some steps for humility as a library