Skip to content

Commit 9695010

Browse files
authored
Merge pull request #169 from Y-Nak/allow-cast
Allow implicit cast between (GenICam) int, float, and enum
2 parents 513cb25 + 9902369 commit 9695010

File tree

9 files changed

+271
-87
lines changed

9 files changed

+271
-87
lines changed

device/src/u3v/async_read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl Drop for AsyncTransfer {
217217
/// timeout, or error, instead of potentially returning early.
218218
///
219219
/// This design is based on
220-
/// https://libusb.sourceforge.io/api-1.0/libusb_mtasync.html#threadwait
220+
/// <https://libusb.sourceforge.io/api-1.0/libusb_mtasync.html#threadwait>
221221
fn poll_completed(
222222
ctx: &impl UsbContext,
223223
timeout: Duration,

genapi/src/boolean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl IBoolean for BooleanNode {
6565
store: &impl NodeStore,
6666
cx: &mut ValueCtxt<T, U>,
6767
) -> GenApiResult<bool> {
68-
let value = self.value.value(device, store, cx)?;
68+
let value: i64 = self.value.value(device, store, cx)?;
6969
if value == self.on_value {
7070
Ok(true)
7171
} else if value == self.off_value {
@@ -102,7 +102,7 @@ impl IBoolean for BooleanNode {
102102
cx: &mut ValueCtxt<T, U>,
103103
) -> GenApiResult<bool> {
104104
Ok(self.elem_base.is_readable(device, store, cx)?
105-
&& self.value.is_readable(device, store, cx)?)
105+
&& IValue::<i64>::is_readable(&self.value, device, store, cx)?)
106106
}
107107

108108
#[tracing::instrument(skip(self, device, store, cx),
@@ -115,7 +115,7 @@ impl IBoolean for BooleanNode {
115115
cx: &mut ValueCtxt<T, U>,
116116
) -> GenApiResult<bool> {
117117
Ok(self.elem_base.is_writable(device, store, cx)?
118-
&& self.value.is_writable(device, store, cx)?)
118+
&& IValue::<i64>::is_writable(&self.value, device, store, cx)?)
119119
}
120120
}
121121

genapi/src/command.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use super::{
66
elem_type::ImmOrPNode,
7-
interface::{ICommand, IInteger, INode},
7+
interface::{ICommand, INode},
88
ivalue::IValue,
99
node_base::{NodeAttributeBase, NodeBase, NodeElementBase},
1010
store::{CacheStore, IntegerId, NodeStore, ValueStore},
@@ -59,7 +59,7 @@ impl ICommand for CommandNode {
5959
) -> GenApiResult<()> {
6060
cx.invalidate_cache_by(self.node_base().id());
6161

62-
let value = self.command_value.value(device, store, cx)?;
62+
let value: i64 = self.command_value.value(device, store, cx)?;
6363
self.value.set_value(value, device, store, cx)
6464
}
6565

@@ -71,15 +71,14 @@ impl ICommand for CommandNode {
7171
store: &impl NodeStore,
7272
cx: &mut ValueCtxt<T, U>,
7373
) -> GenApiResult<bool> {
74-
let nid = match self.value {
74+
let node = match self.value {
7575
ImmOrPNode::Imm(..) => return Ok(true),
7676
ImmOrPNode::PNode(nid) => nid,
7777
};
7878

79-
cx.invalidate_cache_of(nid);
80-
let node = nid.expect_iinteger_kind(store)?;
81-
if node.is_readable(device, store, cx)? {
82-
let command_value = self.command_value.value(device, store, cx)?;
79+
cx.invalidate_cache_of(node);
80+
if IValue::<i64>::is_readable(&node, device, store, cx)? {
81+
let command_value: i64 = self.command_value.value(device, store, cx)?;
8382
let reg_value = node.value(device, store, cx)?;
8483
Ok(command_value != reg_value)
8584
} else {
@@ -97,6 +96,6 @@ impl ICommand for CommandNode {
9796
cx: &mut ValueCtxt<T, U>,
9897
) -> GenApiResult<bool> {
9998
Ok(self.elem_base.is_writable(device, store, cx)?
100-
&& self.value.is_writable(device, store, cx)?)
99+
&& IValue::<i64>::is_writable(&self.value, device, store, cx)?)
101100
}
102101
}

genapi/src/elem_type.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use std::marker::PhantomData;
77

88
use super::{
9-
interface::IInteger,
109
ivalue::IValue,
1110
store::{CacheStore, NodeId, NodeStore, ValueStore},
1211
Device, GenApiResult, ValueCtxt,
@@ -281,7 +280,7 @@ impl AddressKind {
281280
) -> GenApiResult<i64> {
282281
match self {
283282
Self::Address(i) => i.value(device, store, cx),
284-
Self::IntSwissKnife(nid) => nid.expect_iinteger_kind(store)?.value(device, store, cx),
283+
Self::IntSwissKnife(nid) => nid.value(device, store, cx),
285284
Self::PIndex(p_index) => p_index.value(device, store, cx),
286285
}
287286
}
@@ -310,12 +309,10 @@ impl RegPIndex {
310309
store: &impl NodeStore,
311310
cx: &mut ValueCtxt<T, U>,
312311
) -> GenApiResult<i64> {
313-
let base = self
314-
.p_index
315-
.expect_iinteger_kind(store)?
316-
.value(device, store, cx)?;
312+
let base = self.p_index.value(device, store, cx)?;
317313
if let Some(offset) = &self.offset {
318-
Ok(base + offset.value(device, store, cx)?)
314+
let offset: i64 = offset.value(device, store, cx)?;
315+
Ok(base + offset)
319316
} else {
320317
Ok(base)
321318
}

genapi/src/enumeration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl IEnumeration for EnumerationNode {
152152
cx: &mut ValueCtxt<T, U>,
153153
) -> GenApiResult<bool> {
154154
Ok(self.elem_base.is_readable(device, store, cx)?
155-
&& self.value.is_readable(device, store, cx)?)
155+
&& IValue::<i64>::is_readable(&self.value, device, store, cx)?)
156156
}
157157

158158
#[tracing::instrument(skip(self, device, store, cx),
@@ -165,7 +165,7 @@ impl IEnumeration for EnumerationNode {
165165
cx: &mut ValueCtxt<T, U>,
166166
) -> GenApiResult<bool> {
167167
Ok(self.elem_base.is_writable(device, store, cx)?
168-
&& self.value.is_writable(device, store, cx)?)
168+
&& IValue::<i64>::is_writable(&self.value, device, store, cx)?)
169169
}
170170
}
171171

genapi/src/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl IFloat for FloatNode {
198198
cx: &mut ValueCtxt<T, U>,
199199
) -> GenApiResult<bool> {
200200
Ok(self.elem_base.is_readable(device, store, cx)?
201-
&& self.value_kind.is_readable(device, store, cx)?)
201+
&& IValue::<f64>::is_readable(&self.value_kind, device, store, cx)?)
202202
}
203203

204204
#[tracing::instrument(skip(self, device, store, cx),
@@ -211,6 +211,6 @@ impl IFloat for FloatNode {
211211
cx: &mut ValueCtxt<T, U>,
212212
) -> GenApiResult<bool> {
213213
Ok(self.elem_base.is_writable(device, store, cx)?
214-
&& self.value_kind.is_writable(device, store, cx)?)
214+
&& IValue::<f64>::is_writable(&self.value_kind, device, store, cx)?)
215215
}
216216
}

genapi/src/integer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl IInteger for IntegerNode {
188188
cx: &mut ValueCtxt<T, U>,
189189
) -> GenApiResult<bool> {
190190
Ok(self.elem_base.is_readable(device, store, cx)?
191-
&& self.value_kind.is_readable(device, store, cx)?)
191+
&& IValue::<i64>::is_readable(&self.value_kind, device, store, cx)?)
192192
}
193193

194194
#[tracing::instrument(skip(self, device, store, cx),
@@ -201,7 +201,7 @@ impl IInteger for IntegerNode {
201201
cx: &mut ValueCtxt<T, U>,
202202
) -> GenApiResult<bool> {
203203
Ok(self.elem_base.is_writable(device, store, cx)?
204-
&& self.value_kind.is_writable(device, store, cx)?)
204+
&& IValue::<i64>::is_writable(&self.value_kind, device, store, cx)?)
205205
}
206206
}
207207

0 commit comments

Comments
 (0)