]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Avoid blanket impls in bindings builds
authorMatt Corallo <git@bluematt.me>
Mon, 25 Sep 2023 01:05:45 +0000 (01:05 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 1 Oct 2023 00:05:01 +0000 (00:05 +0000)
The C bindings implements `Deref` for all traits, so having a
blanket `Deref` implementation ends up conflicting with this.

lightning/src/routing/scoring.rs

index 1c3f909920a8526c28364d2c35b5438bf97334c2..207e1d69bd98d2b66974884ab1226f1b36562a73 100644 (file)
@@ -133,6 +133,7 @@ pub trait Score : ScoreLookUp + ScoreUpdate $(+ $supertrait)* {}
 #[cfg(not(c_bindings))]
 impl<T: ScoreLookUp + ScoreUpdate $(+ $supertrait)*> Score for T {}
 
+#[cfg(not(c_bindings))]
 impl<S: ScoreLookUp, T: Deref<Target=S>> ScoreLookUp for T {
        type ScoreParams = S::ScoreParams;
        fn channel_penalty_msat(
@@ -142,6 +143,7 @@ impl<S: ScoreLookUp, T: Deref<Target=S>> ScoreLookUp for T {
        }
 }
 
+#[cfg(not(c_bindings))]
 impl<S: ScoreUpdate, T: DerefMut<Target=S>> ScoreUpdate for T {
        fn payment_path_failed(&mut self, path: &Path, short_channel_id: u64) {
                self.deref_mut().payment_path_failed(path, short_channel_id)
@@ -310,6 +312,16 @@ impl<'a, T: 'a + Score> Deref for MultiThreadedScoreLockRead<'a, T> {
        }
 }
 
+#[cfg(c_bindings)]
+impl<'a, T: Score> ScoreLookUp for MultiThreadedScoreLockRead<'a, T> {
+       type ScoreParams = T::ScoreParams;
+       fn channel_penalty_msat(&self, short_channel_id: u64, source: &NodeId,
+               target: &NodeId, usage: ChannelUsage, score_params: &Self::ScoreParams
+       ) -> u64 {
+               self.0.channel_penalty_msat(short_channel_id, source, target, usage, score_params)
+       }
+}
+
 #[cfg(c_bindings)]
 impl<'a, T: Score> Writeable for MultiThreadedScoreLockWrite<'a, T> {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
@@ -333,6 +345,25 @@ impl<'a, T: 'a + Score> DerefMut for MultiThreadedScoreLockWrite<'a, T> {
        }
 }
 
+#[cfg(c_bindings)]
+impl<'a, T: Score> ScoreUpdate for MultiThreadedScoreLockWrite<'a, T> {
+       fn payment_path_failed(&mut self, path: &Path, short_channel_id: u64) {
+               self.0.payment_path_failed(path, short_channel_id)
+       }
+
+       fn payment_path_successful(&mut self, path: &Path) {
+               self.0.payment_path_successful(path)
+       }
+
+       fn probe_failed(&mut self, path: &Path, short_channel_id: u64) {
+               self.0.probe_failed(path, short_channel_id)
+       }
+
+       fn probe_successful(&mut self, path: &Path) {
+               self.0.probe_successful(path)
+       }
+}
+
 
 /// Proposed use of a channel passed as a parameter to [`ScoreLookUp::channel_penalty_msat`].
 #[derive(Clone, Copy, Debug, PartialEq)]