-
-
Notifications
You must be signed in to change notification settings - Fork 140
Refactoring as requested #1050
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
Closed
Closed
Refactoring as requested #1050
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fc3b89e
🚚 zb: rename a function parameter
elmarco 59d49d5
🚚 zb: replace TryFrom<&Address> with a TransportImpl
elmarco f771394
🚚 zb: merge KeyValFmtAdd trait in TransportImpl
elmarco cccbac2
🎨 zb: move top-level public stuff before lower-level & private
elmarco d61763f
♻️ zb: use more appropriate address errors
elmarco 341de4f
♻️ zb: change error::Address to be address::Error
elmarco 2c48f1a
✨ zb: add Transport::into_owned()
elmarco 9e52f8d
✨ zb: implement Clone for Transport
elmarco 50993f9
✨ zb: add OwnedAddress
elmarco 9953ac0
✨ zb: add OwnedAddressListIter
elmarco fe002de
♻️ zb: Builder::address() to take ToOwnedAddress
elmarco e786f63
✨ zb: add address:Guid
elmarco 1e7608d
♻️ zb: make guid() -> Guid
elmarco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| use std::fmt; | ||
|
|
||
| use super::{Error, Result}; | ||
|
|
||
| /// Universally-unique IDs for D-Bus addresses. | ||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
| pub struct Guid([u8; 16]); | ||
|
|
||
| impl Guid { | ||
| /// Create a Guid from the given bytes. | ||
| pub fn new(bytes: [u8; 16]) -> Self { | ||
| Guid(bytes) | ||
| } | ||
|
|
||
| /// Returns a byte slice of this Guid’s contents | ||
| pub fn as_bytes(&self) -> &[u8; 16] { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for Guid { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", | ||
| self.0[0], self.0[1], self.0[2], self.0[3], self.0[4], self.0[5], self.0[6], self.0[7], | ||
| self.0[8], self.0[9], self.0[10], self.0[11], self.0[12], self.0[13], self.0[14], self.0[15]) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&str> for Guid { | ||
| type Error = Error; | ||
|
|
||
| fn try_from(s: &str) -> Result<Self> { | ||
| if s.len() != 32 { | ||
| return Err(Error::InvalidValue("guid".into())); | ||
| } | ||
|
|
||
| let mut bytes = [0u8; 16]; | ||
| for (i, chunk) in s.as_bytes().chunks(2).enumerate() { | ||
| bytes[i] = u8::from_str_radix(std::str::from_utf8(chunk).unwrap(), 16) | ||
| .map_err(|_| Error::InvalidValue("guid".into()))?; | ||
| } | ||
|
|
||
| Ok(Guid(bytes)) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTH? That's not at all what we discussed and I never asked for a new type. I told you to use the existing Guid type. But forget it.