solverforge_solver/planning/scalar/
target.rs1use std::marker::PhantomData;
2
3use super::ScalarEdit;
4
5#[derive(Debug)]
6pub struct ScalarTarget<S> {
7 descriptor_index: usize,
8 variable_name: &'static str,
9 _phantom: PhantomData<fn() -> S>,
10}
11
12impl<S> Clone for ScalarTarget<S> {
13 fn clone(&self) -> Self {
14 *self
15 }
16}
17
18impl<S> Copy for ScalarTarget<S> {}
19
20impl<S> PartialEq for ScalarTarget<S> {
21 fn eq(&self, other: &Self) -> bool {
22 self.descriptor_index == other.descriptor_index && self.variable_name == other.variable_name
23 }
24}
25
26impl<S> Eq for ScalarTarget<S> {}
27
28impl<S> std::hash::Hash for ScalarTarget<S> {
29 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
30 self.descriptor_index.hash(state);
31 self.variable_name.hash(state);
32 }
33}
34
35impl<S> ScalarTarget<S> {
36 #[doc(hidden)]
37 pub const fn from_descriptor_index(
38 descriptor_index: usize,
39 variable_name: &'static str,
40 ) -> Self {
41 Self {
42 descriptor_index,
43 variable_name,
44 _phantom: PhantomData,
45 }
46 }
47
48 #[inline]
49 pub fn set(self, entity_index: usize, to_value: Option<usize>) -> ScalarEdit<S> {
50 ScalarEdit::from_descriptor_index(
51 self.descriptor_index,
52 entity_index,
53 self.variable_name,
54 to_value,
55 )
56 }
57
58 #[doc(hidden)]
59 #[inline]
60 pub fn descriptor_index(self) -> usize {
61 self.descriptor_index
62 }
63
64 #[doc(hidden)]
65 #[inline]
66 pub fn variable_name(self) -> &'static str {
67 self.variable_name
68 }
69}