Skip to content

Commit 1c9d8fd

Browse files
authored
DevMap should not expose cloneable references (#882)
One of the purposes of `DevMap` is to ensure that the datapath does not inappropriately clone out and extend the lifetime of any ports. As it turns out, the code using `DevMap` is doing the right thing, but its API surface is overly permissive and should be making an `Arc::clone` or similar impossible.
1 parent 2e58c13 commit 1c9d8fd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

xde/src/dev_map.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ impl DevMap {
7272
/// Return a reference to an `XdeDev` using its address.
7373
#[inline]
7474
#[must_use]
75-
pub fn get_by_key(&self, key: VniMac) -> Option<&Dev> {
76-
self.devs.get(&key)
75+
pub fn get_by_key(&self, key: VniMac) -> Option<&XdeDev> {
76+
self.devs.get(&key).map(Arc::as_ref)
7777
}
7878

7979
/// Return a reference to an `XdeDev` using its name.
8080
#[inline]
8181
#[must_use]
82-
pub fn get_by_name(&self, name: &str) -> Option<&Dev> {
83-
self.names.get(name)
82+
pub fn get_by_name(&self, name: &str) -> Option<&XdeDev> {
83+
self.names.get(name).map(Arc::as_ref)
8484
}
8585

8686
/// Return an iterator over all `XdeDev`s, sorted by address.
87-
pub fn iter(&self) -> impl Iterator<Item = &Dev> {
88-
self.devs.values()
87+
pub fn iter(&self) -> impl Iterator<Item = &XdeDev> {
88+
self.devs.values().map(Arc::as_ref)
8989
}
9090

9191
/// Return an iterator over all `XdeDev`s, sorted by address.

0 commit comments

Comments
 (0)