Skip to content

Commit

Permalink
Format extension files (#2919)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Mar 7, 2024
1 parent 8ec63c6 commit 9b53544
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ where
unsafe {
// TODO: ideally we can do an AddRef rather than a QI here (via cast)...
// and then we can get rid of the unsafe as well.
Ok(StockIterator {
owner: self.cast()?,
current: 0.into(),
}
.into())
Ok(StockIterator { owner: self.cast()?, current: 0.into() }.into())
}
}
}
Expand Down Expand Up @@ -63,8 +59,7 @@ where
let current = self.current.load(std::sync::atomic::Ordering::Relaxed);

if current < owner.values.len() {
self.current
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
self.current.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
}

Ok(owner.values.len() > current + 1)
Expand All @@ -77,8 +72,7 @@ where
let actual = std::cmp::min(owner.values.len() - current, values.len());
let (values, _) = values.split_at_mut(actual);
values.clone_from_slice(&owner.values[current..current + actual]);
self.current
.fetch_add(actual, std::sync::atomic::Ordering::Relaxed);
self.current.fetch_add(actual, std::sync::atomic::Ordering::Relaxed);
Ok(actual as u32)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ where
unsafe {
// TODO: ideally we can do an AddRef rather than a QI here (via cast)...
// and then we can get rid of the unsafe as well.
Ok(StockMapViewIterator::<K, V> {
_owner: self.cast()?,
current: std::sync::RwLock::new(self.map.iter()),
}
.into())
Ok(StockMapViewIterator::<K, V> { _owner: self.cast()?, current: std::sync::RwLock::new(self.map.iter()) }.into())
}
}
}
Expand All @@ -37,10 +33,7 @@ where
V::Default: Clone,
{
fn Lookup(&self, key: &K::Default) -> windows_core::Result<V> {
let value = self
.map
.get(key)
.ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?;
let value = self.map.get(key).ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?;
V::from_default(value)
}
fn Size(&self) -> windows_core::Result<u32> {
Expand All @@ -49,11 +42,7 @@ where
fn HasKey(&self, key: &K::Default) -> windows_core::Result<bool> {
Ok(self.map.contains_key(key))
}
fn Split(
&self,
first: &mut Option<IMapView<K, V>>,
second: &mut Option<IMapView<K, V>>,
) -> windows_core::Result<()> {
fn Split(&self, first: &mut Option<IMapView<K, V>>, second: &mut Option<IMapView<K, V>>) -> windows_core::Result<()> {
*first = None;
*second = None;
Ok(())
Expand Down Expand Up @@ -83,11 +72,7 @@ where
let mut current = self.current.read().unwrap().clone().peekable();

if let Some((key, value)) = current.peek() {
Ok(StockKeyValuePair {
key: (*key).clone(),
value: (*value).clone(),
}
.into())
Ok(StockKeyValuePair { key: (*key).clone(), value: (*value).clone() }.into())
} else {
Err(windows_core::Error::from(windows_core::imp::E_BOUNDS))
}
Expand All @@ -112,13 +97,7 @@ where

for pair in pairs {
if let Some((key, value)) = current.next() {
*pair = Some(
StockKeyValuePair {
key: (*key).clone(),
value: (*value).clone(),
}
.into(),
);
*pair = Some(StockKeyValuePair { key: (*key).clone(), value: (*value).clone() }.into());
actual += 1;
} else {
break;
Expand Down Expand Up @@ -156,18 +135,15 @@ where
}
}

impl<K, V> TryFrom<std::collections::BTreeMap<K::Default, V::Default>>
for IMapView<K, V>
impl<K, V> TryFrom<std::collections::BTreeMap<K::Default, V::Default>> for IMapView<K, V>
where
K: windows_core::RuntimeType,
V: windows_core::RuntimeType,
K::Default: Clone + Ord,
V::Default: Clone,
{
type Error = windows_core::Error;
fn try_from(
map: std::collections::BTreeMap<K::Default, V::Default>,
) -> windows_core::Result<Self> {
fn try_from(map: std::collections::BTreeMap<K::Default, V::Default>) -> windows_core::Result<Self> {
// TODO: should provide a fallible try_into or more explicit allocator
Ok(StockMapView { map }.into())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ where
unsafe {
// TODO: ideally we can do an AddRef rather than a QI here (via cast)...
// and then we can get rid of the unsafe as well.
Ok(StockVectorViewIterator {
owner: self.cast()?,
current: 0.into(),
}
.into())
Ok(StockVectorViewIterator { owner: self.cast()?, current: 0.into() }.into())
}
}
}
Expand All @@ -31,10 +27,7 @@ where
T::Default: Clone + PartialEq,
{
fn GetAt(&self, index: u32) -> windows_core::Result<T> {
let item = self
.values
.get(index as usize)
.ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?;
let item = self.values.get(index as usize).ok_or_else(|| windows_core::Error::from(windows_core::imp::E_BOUNDS))?;
T::from_default(item)
}
fn Size(&self) -> windows_core::Result<u32> {
Expand Down Expand Up @@ -99,8 +92,7 @@ where
let current = self.current.load(std::sync::atomic::Ordering::Relaxed);

if current < owner.values.len() {
self.current
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
self.current.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
}

Ok(owner.values.len() > current + 1)
Expand All @@ -113,8 +105,7 @@ where
let actual = std::cmp::min(owner.values.len() - current, values.len());
let (values, _) = values.split_at_mut(actual);
values.clone_from_slice(&owner.values[current..current + actual]);
self.current
.fetch_add(actual, std::sync::atomic::Ordering::Relaxed);
self.current.fetch_add(actual, std::sync::atomic::Ordering::Relaxed);
Ok(actual as u32)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

impl From<std::net::SocketAddrV4> for SOCKADDR_INET {
fn from(addr: std::net::SocketAddrV4) -> Self {
SOCKADDR_INET { Ipv4: addr.into() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ impl From<IDispatch> for windows_core::VARIANT {
unsafe {
Self::from_raw(windows_core::imp::VARIANT {
Anonymous: windows_core::imp::VARIANT_0 {
Anonymous: windows_core::imp::VARIANT_0_0 {
vt: 9,
wReserved1: 0,
wReserved2: 0,
wReserved3: 0,
Anonymous: windows_core::imp::VARIANT_0_0_0 { pdispVal: std::mem::transmute(value) },
},
Anonymous: windows_core::imp::VARIANT_0_0 { vt: 9, wReserved1: 0, wReserved2: 0, wReserved3: 0, Anonymous: windows_core::imp::VARIANT_0_0_0 { pdispVal: std::mem::transmute(value) } },
},
})
}
Expand All @@ -21,13 +15,7 @@ impl From<IDispatch> for windows_core::PROPVARIANT {
unsafe {
Self::from_raw(windows_core::imp::PROPVARIANT {
Anonymous: windows_core::imp::PROPVARIANT_0 {
Anonymous: windows_core::imp::PROPVARIANT_0_0 {
vt: 9,
wReserved1: 0,
wReserved2: 0,
wReserved3: 0,
Anonymous: windows_core::imp::PROPVARIANT_0_0_0 { pdispVal: std::mem::transmute(value) },
},
Anonymous: windows_core::imp::PROPVARIANT_0_0 { vt: 9, wReserved1: 0, wReserved2: 0, wReserved3: 0, Anonymous: windows_core::imp::PROPVARIANT_0_0_0 { pdispVal: std::mem::transmute(value) } },
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14048,7 +14048,6 @@ impl From<std::net::SocketAddrV6> for SOCKADDR_IN6 {
}
}
}

impl From<std::net::SocketAddrV4> for SOCKADDR_INET {
fn from(addr: std::net::SocketAddrV4) -> Self {
SOCKADDR_INET { Ipv4: addr.into() }
Expand Down

0 comments on commit 9b53544

Please sign in to comment.