Skip to content
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

Rewrite ::address (import from dbus_addr) #989

Merged
merged 21 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d5164c6
🚚 zb: move address to legacy_address
elmarco Sep 17, 2024
b5293c7
✨ zb: add new address module implementation
elmarco Sep 13, 2024
803a7d5
✨ zb: add From<address::Error>
elmarco Sep 13, 2024
db090f5
💥 zb: change connection, handle ;-separated address
elmarco Jan 30, 2024
175cb5b
♻️ zb: handle TCP transport connection (without legacy_address)
elmarco Jan 31, 2024
b31033d
♻️ zb: move TCP connection test
elmarco Jan 31, 2024
beb6d81
♻️ zb: handle NonceTCP transport (without legacy_address)
elmarco Jan 31, 2024
bb85a98
♻️ zb: move NonceTCP connection test
elmarco Jan 31, 2024
fbed501
♻️ zb: handle Unix transport (without legacy_address)
elmarco Jan 31, 2024
1a93abd
♻️ zb: handle Vsock transport connection (without legacy_address)
elmarco Jan 31, 2024
36020eb
♻️ zb: handle Launchd transport connection (without legacy_address)
elmarco Feb 1, 2024
c62289d
♻️ zb: move Launchd connection test
elmarco Jan 31, 2024
bcaad6e
♻️ zb: make windows_autolaunch_bus_address() return String
elmarco Feb 1, 2024
4d2cdfd
✨ zb: make connect() recursively callable
elmarco Feb 1, 2024
a9dbca6
♻️ zb: handle win32 Autolaunch connection (without legacy_address)
elmarco Feb 1, 2024
00b2c35
♻️ zb: move win32 Autolaunch connection test
elmarco Jan 31, 2024
c2c6d42
🔥 zb: drop legacy_address module
elmarco Jan 31, 2024
dec224c
➖ zb: drop async-recursion dependency
elmarco Sep 18, 2024
979019c
🚚 zb: rename DBusAddr to Address
elmarco Sep 18, 2024
2dc80c4
🩹 zb: make address parsing target-specific
elmarco Sep 24, 2024
0b4362b
🚚 zb: src/connection/connect.rs ⟶ src/connection/connect/mod.rs
elmarco Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions zbus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ nix = { version = "0.29", default-features = false, features = [
# Cargo doesn't provide a way to do that for only specific target OS: https://github.com/rust-lang/cargo/issues/1197.
async-process = "2.2.2"

[target.'cfg(any(target_os = "macos", windows))'.dependencies]
async-recursion = "1.1.1"

[dev-dependencies]
zbus_xml = { path = "../zbus_xml", version = "4.0.0" }
doc-comment = "0.3.3"
Expand Down
81 changes: 81 additions & 0 deletions zbus/src/address/address_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::{borrow::Cow, fmt};

use super::{Address, Error, Result, ToAddresses};

/// A bus address list.
zeenix marked this conversation as resolved.
Show resolved Hide resolved
///
/// D-Bus addresses are `;`-separated.
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct AddressList<'a> {
addr: Cow<'a, str>,
}

impl<'a> ToAddresses<'a> for AddressList<'a> {
type Iter = AddressListIter<'a>;

/// Get an iterator over the D-Bus addresses.
fn to_addresses(&'a self) -> Self::Iter {
AddressListIter::new(self)
}
}

impl<'a> Iterator for AddressListIter<'a> {
type Item = Result<Address<'a>>;

fn next(&mut self) -> Option<Self::Item> {
if self.next_index >= self.data.len() {
return None;
}

let mut addr = &self.data[self.next_index..];
if let Some(end) = addr.find(';') {
addr = &addr[..end];
self.next_index += end + 1;
} else {
self.next_index = self.data.len();
}

Some(Address::try_from(addr))
}
}

/// An iterator of D-Bus addresses.
pub struct AddressListIter<'a> {
data: &'a str,
next_index: usize,
}

impl<'a> AddressListIter<'a> {
fn new(list: &'a AddressList<'_>) -> Self {
Self {
data: list.addr.as_ref(),
next_index: 0,
}
}
}

impl<'a> TryFrom<String> for AddressList<'a> {
type Error = Error;

fn try_from(value: String) -> Result<Self> {
Ok(Self {
addr: Cow::Owned(value),
})
}
}

impl<'a> TryFrom<&'a str> for AddressList<'a> {
type Error = Error;

fn try_from(value: &'a str) -> Result<Self> {
Ok(Self {
addr: Cow::Borrowed(value),
})
}
}

impl fmt::Display for AddressList<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.addr)
}
}
Loading